diff --git a/README.md b/README.md index 260f5152..003fc7fc 100644 --- a/README.md +++ b/README.md @@ -19,20 +19,20 @@ If you are using Maven, add this to your pom.xml file: com.google.cloud google-cloud-essential-contacts - 2.2.0 + 2.2.1 ``` If you are using Gradle without BOM, add this to your dependencies ```Groovy -implementation 'com.google.cloud:google-cloud-essential-contacts:2.2.0' +implementation 'com.google.cloud:google-cloud-essential-contacts:2.2.1' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-essential-contacts" % "2.2.0" +libraryDependencies += "com.google.cloud" % "google-cloud-essential-contacts" % "2.2.1" ``` ## Authentication diff --git a/google-cloud-essential-contacts/pom.xml b/google-cloud-essential-contacts/pom.xml index d58ab187..7c0238ac 100644 --- a/google-cloud-essential-contacts/pom.xml +++ b/google-cloud-essential-contacts/pom.xml @@ -58,6 +58,14 @@ com.google.api gax-grpc + + com.google.api + gax-httpjson + + + com.google.api + gax-httpjson + org.threeten threetenbp @@ -77,12 +85,36 @@ test + + com.google.api + gax + testlib + test + + + com.google.api + gax + testlib + test + com.google.api gax-grpc testlib test + + com.google.api + gax-httpjson + testlib + test + + + com.google.api + gax-httpjson + testlib + test + diff --git a/google-cloud-essential-contacts/src/main/java/com/google/cloud/essentialcontacts/v1/EssentialContactsServiceClient.java b/google-cloud-essential-contacts/src/main/java/com/google/cloud/essentialcontacts/v1/EssentialContactsServiceClient.java index 91bb4529..834b4f5b 100644 --- a/google-cloud-essential-contacts/src/main/java/com/google/cloud/essentialcontacts/v1/EssentialContactsServiceClient.java +++ b/google-cloud-essential-contacts/src/main/java/com/google/cloud/essentialcontacts/v1/EssentialContactsServiceClient.java @@ -103,6 +103,21 @@ * EssentialContactsServiceClient.create(essentialContactsServiceSettings); * } * + *

To use REST (HTTP1.1/JSON) transport (instead of gRPC) for sending and receiving requests over + * the wire: + * + *

{@code
+ * // This snippet has been automatically generated for illustrative purposes only.
+ * // It may require modifications to work in your environment.
+ * EssentialContactsServiceSettings essentialContactsServiceSettings =
+ *     EssentialContactsServiceSettings.newBuilder()
+ *         .setTransportChannelProvider(
+ *             EssentialContactsServiceSettings.defaultHttpJsonTransportProviderBuilder().build())
+ *         .build();
+ * EssentialContactsServiceClient essentialContactsServiceClient =
+ *     EssentialContactsServiceClient.create(essentialContactsServiceSettings);
+ * }
+ * *

Please refer to the GitHub repository's samples for more quickstart code snippets. */ @Generated("by gapic-generator-java") diff --git a/google-cloud-essential-contacts/src/main/java/com/google/cloud/essentialcontacts/v1/EssentialContactsServiceSettings.java b/google-cloud-essential-contacts/src/main/java/com/google/cloud/essentialcontacts/v1/EssentialContactsServiceSettings.java index 3824718c..3df497eb 100644 --- a/google-cloud-essential-contacts/src/main/java/com/google/cloud/essentialcontacts/v1/EssentialContactsServiceSettings.java +++ b/google-cloud-essential-contacts/src/main/java/com/google/cloud/essentialcontacts/v1/EssentialContactsServiceSettings.java @@ -24,6 +24,7 @@ import com.google.api.gax.core.GoogleCredentialsProvider; import com.google.api.gax.core.InstantiatingExecutorProvider; import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider; +import com.google.api.gax.httpjson.InstantiatingHttpJsonChannelProvider; import com.google.api.gax.rpc.ApiClientHeaderProvider; import com.google.api.gax.rpc.ClientContext; import com.google.api.gax.rpc.ClientSettings; @@ -139,11 +140,18 @@ public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilde return EssentialContactsServiceStubSettings.defaultCredentialsProviderBuilder(); } - /** Returns a builder for the default ChannelProvider for this service. */ + /** Returns a builder for the default gRPC ChannelProvider for this service. */ public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() { return EssentialContactsServiceStubSettings.defaultGrpcTransportProviderBuilder(); } + /** Returns a builder for the default REST ChannelProvider for this service. */ + @BetaApi + public static InstantiatingHttpJsonChannelProvider.Builder + defaultHttpJsonTransportProviderBuilder() { + return EssentialContactsServiceStubSettings.defaultHttpJsonTransportProviderBuilder(); + } + public static TransportChannelProvider defaultTransportChannelProvider() { return EssentialContactsServiceStubSettings.defaultTransportChannelProvider(); } @@ -153,11 +161,17 @@ public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuil return EssentialContactsServiceStubSettings.defaultApiClientHeaderProviderBuilder(); } - /** Returns a new builder for this class. */ + /** Returns a new gRPC builder for this class. */ public static Builder newBuilder() { return Builder.createDefault(); } + /** Returns a new REST builder for this class. */ + @BetaApi + public static Builder newHttpJsonBuilder() { + return Builder.createHttpJsonDefault(); + } + /** Returns a new builder for this class. */ public static Builder newBuilder(ClientContext clientContext) { return new Builder(clientContext); @@ -196,6 +210,11 @@ private static Builder createDefault() { return new Builder(EssentialContactsServiceStubSettings.newBuilder()); } + @BetaApi + private static Builder createHttpJsonDefault() { + return new Builder(EssentialContactsServiceStubSettings.newHttpJsonBuilder()); + } + public EssentialContactsServiceStubSettings.Builder getStubSettingsBuilder() { return ((EssentialContactsServiceStubSettings.Builder) getStubSettings()); } diff --git a/google-cloud-essential-contacts/src/main/java/com/google/cloud/essentialcontacts/v1/stub/EssentialContactsServiceStubSettings.java b/google-cloud-essential-contacts/src/main/java/com/google/cloud/essentialcontacts/v1/stub/EssentialContactsServiceStubSettings.java index bf319787..b18b95a3 100644 --- a/google-cloud-essential-contacts/src/main/java/com/google/cloud/essentialcontacts/v1/stub/EssentialContactsServiceStubSettings.java +++ b/google-cloud-essential-contacts/src/main/java/com/google/cloud/essentialcontacts/v1/stub/EssentialContactsServiceStubSettings.java @@ -28,6 +28,9 @@ import com.google.api.gax.grpc.GaxGrpcProperties; import com.google.api.gax.grpc.GrpcTransportChannel; import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider; +import com.google.api.gax.httpjson.GaxHttpJsonProperties; +import com.google.api.gax.httpjson.HttpJsonTransportChannel; +import com.google.api.gax.httpjson.InstantiatingHttpJsonChannelProvider; import com.google.api.gax.retrying.RetrySettings; import com.google.api.gax.rpc.ApiCallContext; import com.google.api.gax.rpc.ApiClientHeaderProvider; @@ -268,6 +271,11 @@ public EssentialContactsServiceStub createStub() throws IOException { .equals(GrpcTransportChannel.getGrpcTransportName())) { return GrpcEssentialContactsServiceStub.create(this); } + if (getTransportChannelProvider() + .getTransportName() + .equals(HttpJsonTransportChannel.getHttpJsonTransportName())) { + return HttpJsonEssentialContactsServiceStub.create(this); + } throw new UnsupportedOperationException( String.format( "Transport not supported: %s", getTransportChannelProvider().getTransportName())); @@ -300,18 +308,25 @@ public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilde .setUseJwtAccessWithScope(true); } - /** Returns a builder for the default ChannelProvider for this service. */ + /** Returns a builder for the default gRPC ChannelProvider for this service. */ public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() { return InstantiatingGrpcChannelProvider.newBuilder() .setMaxInboundMessageSize(Integer.MAX_VALUE); } + /** Returns a builder for the default REST ChannelProvider for this service. */ + @BetaApi + public static InstantiatingHttpJsonChannelProvider.Builder + defaultHttpJsonTransportProviderBuilder() { + return InstantiatingHttpJsonChannelProvider.newBuilder(); + } + public static TransportChannelProvider defaultTransportChannelProvider() { return defaultGrpcTransportProviderBuilder().build(); } @BetaApi("The surface for customizing headers is not stable yet and may change in the future.") - public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { + public static ApiClientHeaderProvider.Builder defaultGrpcApiClientHeaderProviderBuilder() { return ApiClientHeaderProvider.newBuilder() .setGeneratedLibToken( "gapic", GaxProperties.getLibraryVersion(EssentialContactsServiceStubSettings.class)) @@ -319,11 +334,30 @@ public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuil GaxGrpcProperties.getGrpcTokenName(), GaxGrpcProperties.getGrpcVersion()); } - /** Returns a new builder for this class. */ + @BetaApi("The surface for customizing headers is not stable yet and may change in the future.") + public static ApiClientHeaderProvider.Builder defaultHttpJsonApiClientHeaderProviderBuilder() { + return ApiClientHeaderProvider.newBuilder() + .setGeneratedLibToken( + "gapic", GaxProperties.getLibraryVersion(EssentialContactsServiceStubSettings.class)) + .setTransportToken( + GaxHttpJsonProperties.getHttpJsonTokenName(), + GaxHttpJsonProperties.getHttpJsonVersion()); + } + + public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { + return EssentialContactsServiceStubSettings.defaultGrpcApiClientHeaderProviderBuilder(); + } + + /** Returns a new gRPC builder for this class. */ public static Builder newBuilder() { return Builder.createDefault(); } + /** Returns a new REST builder for this class. */ + public static Builder newHttpJsonBuilder() { + return Builder.createHttpJsonDefault(); + } + /** Returns a new builder for this class. */ public static Builder newBuilder(ClientContext clientContext) { return new Builder(clientContext); @@ -464,6 +498,19 @@ private static Builder createDefault() { return initDefaults(builder); } + private static Builder createHttpJsonDefault() { + Builder builder = new Builder(((ClientContext) null)); + + builder.setTransportChannelProvider(defaultHttpJsonTransportProviderBuilder().build()); + builder.setCredentialsProvider(defaultCredentialsProviderBuilder().build()); + builder.setInternalHeaderProvider(defaultHttpJsonApiClientHeaderProviderBuilder().build()); + builder.setEndpoint(getDefaultEndpoint()); + builder.setMtlsEndpoint(getDefaultMtlsEndpoint()); + builder.setSwitchToMtlsEndpointAllowed(true); + + return initDefaults(builder); + } + private static Builder initDefaults(Builder builder) { builder .createContactSettings() diff --git a/google-cloud-essential-contacts/src/main/java/com/google/cloud/essentialcontacts/v1/stub/HttpJsonEssentialContactsServiceCallableFactory.java b/google-cloud-essential-contacts/src/main/java/com/google/cloud/essentialcontacts/v1/stub/HttpJsonEssentialContactsServiceCallableFactory.java new file mode 100644 index 00000000..e839b388 --- /dev/null +++ b/google-cloud-essential-contacts/src/main/java/com/google/cloud/essentialcontacts/v1/stub/HttpJsonEssentialContactsServiceCallableFactory.java @@ -0,0 +1,105 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.essentialcontacts.v1.stub; + +import com.google.api.core.BetaApi; +import com.google.api.gax.httpjson.HttpJsonCallSettings; +import com.google.api.gax.httpjson.HttpJsonCallableFactory; +import com.google.api.gax.httpjson.HttpJsonOperationSnapshotCallable; +import com.google.api.gax.httpjson.HttpJsonStubCallableFactory; +import com.google.api.gax.httpjson.longrunning.stub.OperationsStub; +import com.google.api.gax.rpc.BatchingCallSettings; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.OperationCallSettings; +import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.PagedCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallable; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.longrunning.Operation; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +/** + * REST callable factory implementation for the EssentialContactsService service API. + * + *

This class is for advanced usage. + */ +@Generated("by gapic-generator-java") +@BetaApi +public class HttpJsonEssentialContactsServiceCallableFactory + implements HttpJsonStubCallableFactory { + + @Override + public UnaryCallable createUnaryCallable( + HttpJsonCallSettings httpJsonCallSettings, + UnaryCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createUnaryCallable( + httpJsonCallSettings, callSettings, clientContext); + } + + @Override + public + UnaryCallable createPagedCallable( + HttpJsonCallSettings httpJsonCallSettings, + PagedCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createPagedCallable( + httpJsonCallSettings, callSettings, clientContext); + } + + @Override + public UnaryCallable createBatchingCallable( + HttpJsonCallSettings httpJsonCallSettings, + BatchingCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createBatchingCallable( + httpJsonCallSettings, callSettings, clientContext); + } + + @BetaApi( + "The surface for long-running operations is not stable yet and may change in the future.") + @Override + public + OperationCallable createOperationCallable( + HttpJsonCallSettings httpJsonCallSettings, + OperationCallSettings callSettings, + ClientContext clientContext, + OperationsStub operationsStub) { + UnaryCallable innerCallable = + HttpJsonCallableFactory.createBaseUnaryCallable( + httpJsonCallSettings, callSettings.getInitialCallSettings(), clientContext); + HttpJsonOperationSnapshotCallable initialCallable = + new HttpJsonOperationSnapshotCallable( + innerCallable, + httpJsonCallSettings.getMethodDescriptor().getOperationSnapshotFactory()); + return HttpJsonCallableFactory.createOperationCallable( + callSettings, clientContext, operationsStub.longRunningClient(), initialCallable); + } + + @Override + public + ServerStreamingCallable createServerStreamingCallable( + HttpJsonCallSettings httpJsonCallSettings, + ServerStreamingCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createServerStreamingCallable( + httpJsonCallSettings, callSettings, clientContext); + } +} diff --git a/google-cloud-essential-contacts/src/main/java/com/google/cloud/essentialcontacts/v1/stub/HttpJsonEssentialContactsServiceStub.java b/google-cloud-essential-contacts/src/main/java/com/google/cloud/essentialcontacts/v1/stub/HttpJsonEssentialContactsServiceStub.java new file mode 100644 index 00000000..07f8f531 --- /dev/null +++ b/google-cloud-essential-contacts/src/main/java/com/google/cloud/essentialcontacts/v1/stub/HttpJsonEssentialContactsServiceStub.java @@ -0,0 +1,560 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.essentialcontacts.v1.stub; + +import static com.google.cloud.essentialcontacts.v1.EssentialContactsServiceClient.ComputeContactsPagedResponse; +import static com.google.cloud.essentialcontacts.v1.EssentialContactsServiceClient.ListContactsPagedResponse; + +import com.google.api.core.BetaApi; +import com.google.api.core.InternalApi; +import com.google.api.gax.core.BackgroundResource; +import com.google.api.gax.core.BackgroundResourceAggregation; +import com.google.api.gax.httpjson.ApiMethodDescriptor; +import com.google.api.gax.httpjson.HttpJsonCallSettings; +import com.google.api.gax.httpjson.HttpJsonStubCallableFactory; +import com.google.api.gax.httpjson.ProtoMessageRequestFormatter; +import com.google.api.gax.httpjson.ProtoMessageResponseParser; +import com.google.api.gax.httpjson.ProtoRestSerializer; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.cloud.essentialcontacts.v1.ComputeContactsRequest; +import com.google.cloud.essentialcontacts.v1.ComputeContactsResponse; +import com.google.cloud.essentialcontacts.v1.Contact; +import com.google.cloud.essentialcontacts.v1.CreateContactRequest; +import com.google.cloud.essentialcontacts.v1.DeleteContactRequest; +import com.google.cloud.essentialcontacts.v1.GetContactRequest; +import com.google.cloud.essentialcontacts.v1.ListContactsRequest; +import com.google.cloud.essentialcontacts.v1.ListContactsResponse; +import com.google.cloud.essentialcontacts.v1.SendTestMessageRequest; +import com.google.cloud.essentialcontacts.v1.UpdateContactRequest; +import com.google.protobuf.Empty; +import com.google.protobuf.TypeRegistry; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.TimeUnit; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +/** + * REST stub implementation for the EssentialContactsService service API. + * + *

This class is for advanced usage and reflects the underlying API directly. + */ +@Generated("by gapic-generator-java") +@BetaApi +public class HttpJsonEssentialContactsServiceStub extends EssentialContactsServiceStub { + private static final TypeRegistry typeRegistry = TypeRegistry.newBuilder().build(); + + private static final ApiMethodDescriptor + createContactMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.cloud.essentialcontacts.v1.EssentialContactsService/CreateContact") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{parent=projects/*}/contacts", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "parent", request.getParent()); + return fields; + }) + .setAdditionalPaths( + "/v1/{parent=folders/*}/contacts", + "/v1/{parent=organizations/*}/contacts") + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create().toBody("contact", request.getContact())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Contact.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + updateContactMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.cloud.essentialcontacts.v1.EssentialContactsService/UpdateContact") + .setHttpMethod("PATCH") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{contact.name=projects/*/contacts/*}", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam( + fields, "contact.name", request.getContact().getName()); + return fields; + }) + .setAdditionalPaths( + "/v1/{contact.name=folders/*/contacts/*}", + "/v1/{contact.name=organizations/*/contacts/*}") + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "updateMask", request.getUpdateMask()); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create().toBody("contact", request.getContact())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Contact.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + listContactsMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.cloud.essentialcontacts.v1.EssentialContactsService/ListContacts") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{parent=projects/*}/contacts", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "parent", request.getParent()); + return fields; + }) + .setAdditionalPaths( + "/v1/{parent=folders/*}/contacts", + "/v1/{parent=organizations/*}/contacts") + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "pageSize", request.getPageSize()); + serializer.putQueryParam(fields, "pageToken", request.getPageToken()); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(ListContactsResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor getContactMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.cloud.essentialcontacts.v1.EssentialContactsService/GetContact") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{name=projects/*/contacts/*}", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "name", request.getName()); + return fields; + }) + .setAdditionalPaths( + "/v1/{name=folders/*/contacts/*}", "/v1/{name=organizations/*/contacts/*}") + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Contact.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + deleteContactMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.cloud.essentialcontacts.v1.EssentialContactsService/DeleteContact") + .setHttpMethod("DELETE") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{name=projects/*/contacts/*}", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "name", request.getName()); + return fields; + }) + .setAdditionalPaths( + "/v1/{name=folders/*/contacts/*}", + "/v1/{name=organizations/*/contacts/*}") + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Empty.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + computeContactsMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.cloud.essentialcontacts.v1.EssentialContactsService/ComputeContacts") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{parent=projects/*}/contacts:compute", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "parent", request.getParent()); + return fields; + }) + .setAdditionalPaths( + "/v1/{parent=folders/*}/contacts:compute", + "/v1/{parent=organizations/*}/contacts:compute") + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam( + fields, + "notificationCategories", + request.getNotificationCategoriesList()); + serializer.putQueryParam(fields, "pageSize", request.getPageSize()); + serializer.putQueryParam(fields, "pageToken", request.getPageToken()); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(ComputeContactsResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + sendTestMessageMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.cloud.essentialcontacts.v1.EssentialContactsService/SendTestMessage") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{resource=projects/*}/contacts:sendTestMessage", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "resource", request.getResource()); + return fields; + }) + .setAdditionalPaths( + "/v1/{resource=folders/*}/contacts:sendTestMessage", + "/v1/{resource=organizations/*}/contacts:sendTestMessage") + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("*", request.toBuilder().clearResource().build())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Empty.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private final UnaryCallable createContactCallable; + private final UnaryCallable updateContactCallable; + private final UnaryCallable listContactsCallable; + private final UnaryCallable + listContactsPagedCallable; + private final UnaryCallable getContactCallable; + private final UnaryCallable deleteContactCallable; + private final UnaryCallable + computeContactsCallable; + private final UnaryCallable + computeContactsPagedCallable; + private final UnaryCallable sendTestMessageCallable; + + private final BackgroundResource backgroundResources; + private final HttpJsonStubCallableFactory callableFactory; + + public static final HttpJsonEssentialContactsServiceStub create( + EssentialContactsServiceStubSettings settings) throws IOException { + return new HttpJsonEssentialContactsServiceStub(settings, ClientContext.create(settings)); + } + + public static final HttpJsonEssentialContactsServiceStub create(ClientContext clientContext) + throws IOException { + return new HttpJsonEssentialContactsServiceStub( + EssentialContactsServiceStubSettings.newHttpJsonBuilder().build(), clientContext); + } + + public static final HttpJsonEssentialContactsServiceStub create( + ClientContext clientContext, HttpJsonStubCallableFactory callableFactory) throws IOException { + return new HttpJsonEssentialContactsServiceStub( + EssentialContactsServiceStubSettings.newHttpJsonBuilder().build(), + clientContext, + callableFactory); + } + + /** + * Constructs an instance of HttpJsonEssentialContactsServiceStub, using the given settings. This + * is protected so that it is easy to make a subclass, but otherwise, the static factory methods + * should be preferred. + */ + protected HttpJsonEssentialContactsServiceStub( + EssentialContactsServiceStubSettings settings, ClientContext clientContext) + throws IOException { + this(settings, clientContext, new HttpJsonEssentialContactsServiceCallableFactory()); + } + + /** + * Constructs an instance of HttpJsonEssentialContactsServiceStub, using the given settings. This + * is protected so that it is easy to make a subclass, but otherwise, the static factory methods + * should be preferred. + */ + protected HttpJsonEssentialContactsServiceStub( + EssentialContactsServiceStubSettings settings, + ClientContext clientContext, + HttpJsonStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; + + HttpJsonCallSettings createContactTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(createContactMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings updateContactTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(updateContactMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings listContactsTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(listContactsMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings getContactTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(getContactMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings deleteContactTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(deleteContactMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + computeContactsTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(computeContactsMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings sendTestMessageTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(sendTestMessageMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + + this.createContactCallable = + callableFactory.createUnaryCallable( + createContactTransportSettings, settings.createContactSettings(), clientContext); + this.updateContactCallable = + callableFactory.createUnaryCallable( + updateContactTransportSettings, settings.updateContactSettings(), clientContext); + this.listContactsCallable = + callableFactory.createUnaryCallable( + listContactsTransportSettings, settings.listContactsSettings(), clientContext); + this.listContactsPagedCallable = + callableFactory.createPagedCallable( + listContactsTransportSettings, settings.listContactsSettings(), clientContext); + this.getContactCallable = + callableFactory.createUnaryCallable( + getContactTransportSettings, settings.getContactSettings(), clientContext); + this.deleteContactCallable = + callableFactory.createUnaryCallable( + deleteContactTransportSettings, settings.deleteContactSettings(), clientContext); + this.computeContactsCallable = + callableFactory.createUnaryCallable( + computeContactsTransportSettings, settings.computeContactsSettings(), clientContext); + this.computeContactsPagedCallable = + callableFactory.createPagedCallable( + computeContactsTransportSettings, settings.computeContactsSettings(), clientContext); + this.sendTestMessageCallable = + callableFactory.createUnaryCallable( + sendTestMessageTransportSettings, settings.sendTestMessageSettings(), clientContext); + + this.backgroundResources = + new BackgroundResourceAggregation(clientContext.getBackgroundResources()); + } + + @InternalApi + public static List getMethodDescriptors() { + List methodDescriptors = new ArrayList<>(); + methodDescriptors.add(createContactMethodDescriptor); + methodDescriptors.add(updateContactMethodDescriptor); + methodDescriptors.add(listContactsMethodDescriptor); + methodDescriptors.add(getContactMethodDescriptor); + methodDescriptors.add(deleteContactMethodDescriptor); + methodDescriptors.add(computeContactsMethodDescriptor); + methodDescriptors.add(sendTestMessageMethodDescriptor); + return methodDescriptors; + } + + @Override + public UnaryCallable createContactCallable() { + return createContactCallable; + } + + @Override + public UnaryCallable updateContactCallable() { + return updateContactCallable; + } + + @Override + public UnaryCallable listContactsCallable() { + return listContactsCallable; + } + + @Override + public UnaryCallable listContactsPagedCallable() { + return listContactsPagedCallable; + } + + @Override + public UnaryCallable getContactCallable() { + return getContactCallable; + } + + @Override + public UnaryCallable deleteContactCallable() { + return deleteContactCallable; + } + + @Override + public UnaryCallable computeContactsCallable() { + return computeContactsCallable; + } + + @Override + public UnaryCallable + computeContactsPagedCallable() { + return computeContactsPagedCallable; + } + + @Override + public UnaryCallable sendTestMessageCallable() { + return sendTestMessageCallable; + } + + @Override + public final void close() { + try { + backgroundResources.close(); + } catch (RuntimeException e) { + throw e; + } catch (Exception e) { + throw new IllegalStateException("Failed to close resource", e); + } + } + + @Override + public void shutdown() { + backgroundResources.shutdown(); + } + + @Override + public boolean isShutdown() { + return backgroundResources.isShutdown(); + } + + @Override + public boolean isTerminated() { + return backgroundResources.isTerminated(); + } + + @Override + public void shutdownNow() { + backgroundResources.shutdownNow(); + } + + @Override + public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException { + return backgroundResources.awaitTermination(duration, unit); + } +} diff --git a/google-cloud-essential-contacts/src/test/java/com/google/cloud/essentialcontacts/v1/EssentialContactsServiceClientHttpJsonTest.java b/google-cloud-essential-contacts/src/test/java/com/google/cloud/essentialcontacts/v1/EssentialContactsServiceClientHttpJsonTest.java new file mode 100644 index 00000000..5bafc8e6 --- /dev/null +++ b/google-cloud-essential-contacts/src/test/java/com/google/cloud/essentialcontacts/v1/EssentialContactsServiceClientHttpJsonTest.java @@ -0,0 +1,843 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.essentialcontacts.v1; + +import static com.google.cloud.essentialcontacts.v1.EssentialContactsServiceClient.ComputeContactsPagedResponse; +import static com.google.cloud.essentialcontacts.v1.EssentialContactsServiceClient.ListContactsPagedResponse; + +import com.google.api.gax.core.NoCredentialsProvider; +import com.google.api.gax.httpjson.GaxHttpJsonProperties; +import com.google.api.gax.httpjson.testing.MockHttpService; +import com.google.api.gax.rpc.ApiClientHeaderProvider; +import com.google.api.gax.rpc.ApiException; +import com.google.api.gax.rpc.ApiExceptionFactory; +import com.google.api.gax.rpc.InvalidArgumentException; +import com.google.api.gax.rpc.StatusCode; +import com.google.api.gax.rpc.testing.FakeStatusCode; +import com.google.cloud.essentialcontacts.v1.stub.HttpJsonEssentialContactsServiceStub; +import com.google.common.collect.Lists; +import com.google.protobuf.Empty; +import com.google.protobuf.FieldMask; +import com.google.protobuf.Timestamp; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import javax.annotation.Generated; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +@Generated("by gapic-generator-java") +public class EssentialContactsServiceClientHttpJsonTest { + private static MockHttpService mockService; + private static EssentialContactsServiceClient client; + + @BeforeClass + public static void startStaticServer() throws IOException { + mockService = + new MockHttpService( + HttpJsonEssentialContactsServiceStub.getMethodDescriptors(), + EssentialContactsServiceSettings.getDefaultEndpoint()); + EssentialContactsServiceSettings settings = + EssentialContactsServiceSettings.newHttpJsonBuilder() + .setTransportChannelProvider( + EssentialContactsServiceSettings.defaultHttpJsonTransportProviderBuilder() + .setHttpTransport(mockService) + .build()) + .setCredentialsProvider(NoCredentialsProvider.create()) + .build(); + client = EssentialContactsServiceClient.create(settings); + } + + @AfterClass + public static void stopServer() { + client.close(); + } + + @Before + public void setUp() {} + + @After + public void tearDown() throws Exception { + mockService.reset(); + } + + @Test + public void createContactTest() throws Exception { + Contact expectedResponse = + Contact.newBuilder() + .setName(ContactName.ofProjectContactName("[PROJECT]", "[CONTACT]").toString()) + .setEmail("email96619420") + .addAllNotificationCategorySubscriptions(new ArrayList()) + .setLanguageTag("languageTag-1175857886") + .setValidationState(ValidationState.forNumber(0)) + .setValidateTime(Timestamp.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + FolderName parent = FolderName.of("[FOLDER]"); + Contact contact = Contact.newBuilder().build(); + + Contact actualResponse = client.createContact(parent, contact); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void createContactExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + FolderName parent = FolderName.of("[FOLDER]"); + Contact contact = Contact.newBuilder().build(); + client.createContact(parent, contact); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void createContactTest2() throws Exception { + Contact expectedResponse = + Contact.newBuilder() + .setName(ContactName.ofProjectContactName("[PROJECT]", "[CONTACT]").toString()) + .setEmail("email96619420") + .addAllNotificationCategorySubscriptions(new ArrayList()) + .setLanguageTag("languageTag-1175857886") + .setValidationState(ValidationState.forNumber(0)) + .setValidateTime(Timestamp.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + OrganizationName parent = OrganizationName.of("[ORGANIZATION]"); + Contact contact = Contact.newBuilder().build(); + + Contact actualResponse = client.createContact(parent, contact); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void createContactExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + OrganizationName parent = OrganizationName.of("[ORGANIZATION]"); + Contact contact = Contact.newBuilder().build(); + client.createContact(parent, contact); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void createContactTest3() throws Exception { + Contact expectedResponse = + Contact.newBuilder() + .setName(ContactName.ofProjectContactName("[PROJECT]", "[CONTACT]").toString()) + .setEmail("email96619420") + .addAllNotificationCategorySubscriptions(new ArrayList()) + .setLanguageTag("languageTag-1175857886") + .setValidationState(ValidationState.forNumber(0)) + .setValidateTime(Timestamp.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + ProjectName parent = ProjectName.of("[PROJECT]"); + Contact contact = Contact.newBuilder().build(); + + Contact actualResponse = client.createContact(parent, contact); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void createContactExceptionTest3() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + ProjectName parent = ProjectName.of("[PROJECT]"); + Contact contact = Contact.newBuilder().build(); + client.createContact(parent, contact); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void createContactTest4() throws Exception { + Contact expectedResponse = + Contact.newBuilder() + .setName(ContactName.ofProjectContactName("[PROJECT]", "[CONTACT]").toString()) + .setEmail("email96619420") + .addAllNotificationCategorySubscriptions(new ArrayList()) + .setLanguageTag("languageTag-1175857886") + .setValidationState(ValidationState.forNumber(0)) + .setValidateTime(Timestamp.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + String parent = "projects/project-2353"; + Contact contact = Contact.newBuilder().build(); + + Contact actualResponse = client.createContact(parent, contact); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void createContactExceptionTest4() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String parent = "projects/project-2353"; + Contact contact = Contact.newBuilder().build(); + client.createContact(parent, contact); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void updateContactTest() throws Exception { + Contact expectedResponse = + Contact.newBuilder() + .setName(ContactName.ofProjectContactName("[PROJECT]", "[CONTACT]").toString()) + .setEmail("email96619420") + .addAllNotificationCategorySubscriptions(new ArrayList()) + .setLanguageTag("languageTag-1175857886") + .setValidationState(ValidationState.forNumber(0)) + .setValidateTime(Timestamp.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + Contact contact = + Contact.newBuilder() + .setName(ContactName.ofProjectContactName("[PROJECT]", "[CONTACT]").toString()) + .setEmail("email96619420") + .addAllNotificationCategorySubscriptions(new ArrayList()) + .setLanguageTag("languageTag-1175857886") + .setValidationState(ValidationState.forNumber(0)) + .setValidateTime(Timestamp.newBuilder().build()) + .build(); + FieldMask updateMask = FieldMask.newBuilder().build(); + + Contact actualResponse = client.updateContact(contact, updateMask); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void updateContactExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + Contact contact = + Contact.newBuilder() + .setName(ContactName.ofProjectContactName("[PROJECT]", "[CONTACT]").toString()) + .setEmail("email96619420") + .addAllNotificationCategorySubscriptions(new ArrayList()) + .setLanguageTag("languageTag-1175857886") + .setValidationState(ValidationState.forNumber(0)) + .setValidateTime(Timestamp.newBuilder().build()) + .build(); + FieldMask updateMask = FieldMask.newBuilder().build(); + client.updateContact(contact, updateMask); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listContactsTest() throws Exception { + Contact responsesElement = Contact.newBuilder().build(); + ListContactsResponse expectedResponse = + ListContactsResponse.newBuilder() + .setNextPageToken("") + .addAllContacts(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + FolderName parent = FolderName.of("[FOLDER]"); + + ListContactsPagedResponse pagedListResponse = client.listContacts(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getContactsList().get(0), resources.get(0)); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void listContactsExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + FolderName parent = FolderName.of("[FOLDER]"); + client.listContacts(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listContactsTest2() throws Exception { + Contact responsesElement = Contact.newBuilder().build(); + ListContactsResponse expectedResponse = + ListContactsResponse.newBuilder() + .setNextPageToken("") + .addAllContacts(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + OrganizationName parent = OrganizationName.of("[ORGANIZATION]"); + + ListContactsPagedResponse pagedListResponse = client.listContacts(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getContactsList().get(0), resources.get(0)); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void listContactsExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + OrganizationName parent = OrganizationName.of("[ORGANIZATION]"); + client.listContacts(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listContactsTest3() throws Exception { + Contact responsesElement = Contact.newBuilder().build(); + ListContactsResponse expectedResponse = + ListContactsResponse.newBuilder() + .setNextPageToken("") + .addAllContacts(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + ProjectName parent = ProjectName.of("[PROJECT]"); + + ListContactsPagedResponse pagedListResponse = client.listContacts(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getContactsList().get(0), resources.get(0)); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void listContactsExceptionTest3() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + ProjectName parent = ProjectName.of("[PROJECT]"); + client.listContacts(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listContactsTest4() throws Exception { + Contact responsesElement = Contact.newBuilder().build(); + ListContactsResponse expectedResponse = + ListContactsResponse.newBuilder() + .setNextPageToken("") + .addAllContacts(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + String parent = "projects/project-2353"; + + ListContactsPagedResponse pagedListResponse = client.listContacts(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getContactsList().get(0), resources.get(0)); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void listContactsExceptionTest4() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String parent = "projects/project-2353"; + client.listContacts(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getContactTest() throws Exception { + Contact expectedResponse = + Contact.newBuilder() + .setName(ContactName.ofProjectContactName("[PROJECT]", "[CONTACT]").toString()) + .setEmail("email96619420") + .addAllNotificationCategorySubscriptions(new ArrayList()) + .setLanguageTag("languageTag-1175857886") + .setValidationState(ValidationState.forNumber(0)) + .setValidateTime(Timestamp.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + ContactName name = ContactName.ofProjectContactName("[PROJECT]", "[CONTACT]"); + + Contact actualResponse = client.getContact(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void getContactExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + ContactName name = ContactName.ofProjectContactName("[PROJECT]", "[CONTACT]"); + client.getContact(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getContactTest2() throws Exception { + Contact expectedResponse = + Contact.newBuilder() + .setName(ContactName.ofProjectContactName("[PROJECT]", "[CONTACT]").toString()) + .setEmail("email96619420") + .addAllNotificationCategorySubscriptions(new ArrayList()) + .setLanguageTag("languageTag-1175857886") + .setValidationState(ValidationState.forNumber(0)) + .setValidateTime(Timestamp.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + String name = "projects/project-1347/contacts/contact-1347"; + + Contact actualResponse = client.getContact(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void getContactExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = "projects/project-1347/contacts/contact-1347"; + client.getContact(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void deleteContactTest() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + mockService.addResponse(expectedResponse); + + ContactName name = ContactName.ofProjectContactName("[PROJECT]", "[CONTACT]"); + + client.deleteContact(name); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void deleteContactExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + ContactName name = ContactName.ofProjectContactName("[PROJECT]", "[CONTACT]"); + client.deleteContact(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void deleteContactTest2() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + mockService.addResponse(expectedResponse); + + String name = "projects/project-1347/contacts/contact-1347"; + + client.deleteContact(name); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void deleteContactExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = "projects/project-1347/contacts/contact-1347"; + client.deleteContact(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void computeContactsTest() throws Exception { + Contact responsesElement = Contact.newBuilder().build(); + ComputeContactsResponse expectedResponse = + ComputeContactsResponse.newBuilder() + .setNextPageToken("") + .addAllContacts(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + ComputeContactsRequest request = + ComputeContactsRequest.newBuilder() + .setParent(ProjectName.of("[PROJECT]").toString()) + .addAllNotificationCategories(new ArrayList()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + + ComputeContactsPagedResponse pagedListResponse = client.computeContacts(request); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getContactsList().get(0), resources.get(0)); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void computeContactsExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + ComputeContactsRequest request = + ComputeContactsRequest.newBuilder() + .setParent(ProjectName.of("[PROJECT]").toString()) + .addAllNotificationCategories(new ArrayList()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + client.computeContacts(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void sendTestMessageTest() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + mockService.addResponse(expectedResponse); + + SendTestMessageRequest request = + SendTestMessageRequest.newBuilder() + .addAllContacts(new ArrayList()) + .setResource(ProjectName.of("[PROJECT]").toString()) + .setNotificationCategory(NotificationCategory.forNumber(0)) + .build(); + + client.sendTestMessage(request); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void sendTestMessageExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + SendTestMessageRequest request = + SendTestMessageRequest.newBuilder() + .addAllContacts(new ArrayList()) + .setResource(ProjectName.of("[PROJECT]").toString()) + .setNotificationCategory(NotificationCategory.forNumber(0)) + .build(); + client.sendTestMessage(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } +} diff --git a/samples/snippets/generated/com/google/cloud/essentialcontacts/v1/essentialcontactsserviceclient/computecontacts/AsyncComputeContacts.java b/samples/snippets/generated/com/google/cloud/essentialcontacts/v1/essentialcontactsserviceclient/computecontacts/AsyncComputeContacts.java new file mode 100644 index 00000000..a6999732 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/essentialcontacts/v1/essentialcontactsserviceclient/computecontacts/AsyncComputeContacts.java @@ -0,0 +1,55 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.essentialcontacts.v1.samples; + +// [START essentialcontacts_v1_generated_essentialcontactsserviceclient_computecontacts_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.essentialcontacts.v1.ComputeContactsRequest; +import com.google.cloud.essentialcontacts.v1.Contact; +import com.google.cloud.essentialcontacts.v1.EssentialContactsServiceClient; +import com.google.cloud.essentialcontacts.v1.NotificationCategory; +import com.google.cloud.essentialcontacts.v1.ProjectName; +import java.util.ArrayList; + +public class AsyncComputeContacts { + + public static void main(String[] args) throws Exception { + asyncComputeContacts(); + } + + public static void asyncComputeContacts() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (EssentialContactsServiceClient essentialContactsServiceClient = + EssentialContactsServiceClient.create()) { + ComputeContactsRequest request = + ComputeContactsRequest.newBuilder() + .setParent(ProjectName.of("[PROJECT]").toString()) + .addAllNotificationCategories(new ArrayList()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + ApiFuture future = + essentialContactsServiceClient.computeContactsPagedCallable().futureCall(request); + // Do something. + for (Contact element : future.get().iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END essentialcontacts_v1_generated_essentialcontactsserviceclient_computecontacts_async] diff --git a/samples/snippets/generated/com/google/cloud/essentialcontacts/v1/essentialcontactsserviceclient/computecontacts/AsyncComputeContactsPaged.java b/samples/snippets/generated/com/google/cloud/essentialcontacts/v1/essentialcontactsserviceclient/computecontacts/AsyncComputeContactsPaged.java new file mode 100644 index 00000000..9cbff70b --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/essentialcontacts/v1/essentialcontactsserviceclient/computecontacts/AsyncComputeContactsPaged.java @@ -0,0 +1,63 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.essentialcontacts.v1.samples; + +// [START essentialcontacts_v1_generated_essentialcontactsserviceclient_computecontacts_paged_async] +import com.google.cloud.essentialcontacts.v1.ComputeContactsRequest; +import com.google.cloud.essentialcontacts.v1.ComputeContactsResponse; +import com.google.cloud.essentialcontacts.v1.Contact; +import com.google.cloud.essentialcontacts.v1.EssentialContactsServiceClient; +import com.google.cloud.essentialcontacts.v1.NotificationCategory; +import com.google.cloud.essentialcontacts.v1.ProjectName; +import com.google.common.base.Strings; +import java.util.ArrayList; + +public class AsyncComputeContactsPaged { + + public static void main(String[] args) throws Exception { + asyncComputeContactsPaged(); + } + + public static void asyncComputeContactsPaged() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (EssentialContactsServiceClient essentialContactsServiceClient = + EssentialContactsServiceClient.create()) { + ComputeContactsRequest request = + ComputeContactsRequest.newBuilder() + .setParent(ProjectName.of("[PROJECT]").toString()) + .addAllNotificationCategories(new ArrayList()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + while (true) { + ComputeContactsResponse response = + essentialContactsServiceClient.computeContactsCallable().call(request); + for (Contact element : response.getContactsList()) { + // doThingsWith(element); + } + String nextPageToken = response.getNextPageToken(); + if (!Strings.isNullOrEmpty(nextPageToken)) { + request = request.toBuilder().setPageToken(nextPageToken).build(); + } else { + break; + } + } + } + } +} +// [END essentialcontacts_v1_generated_essentialcontactsserviceclient_computecontacts_paged_async] diff --git a/samples/snippets/generated/com/google/cloud/essentialcontacts/v1/essentialcontactsserviceclient/computecontacts/SyncComputeContacts.java b/samples/snippets/generated/com/google/cloud/essentialcontacts/v1/essentialcontactsserviceclient/computecontacts/SyncComputeContacts.java new file mode 100644 index 00000000..3370b1e0 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/essentialcontacts/v1/essentialcontactsserviceclient/computecontacts/SyncComputeContacts.java @@ -0,0 +1,51 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.essentialcontacts.v1.samples; + +// [START essentialcontacts_v1_generated_essentialcontactsserviceclient_computecontacts_sync] +import com.google.cloud.essentialcontacts.v1.ComputeContactsRequest; +import com.google.cloud.essentialcontacts.v1.Contact; +import com.google.cloud.essentialcontacts.v1.EssentialContactsServiceClient; +import com.google.cloud.essentialcontacts.v1.NotificationCategory; +import com.google.cloud.essentialcontacts.v1.ProjectName; +import java.util.ArrayList; + +public class SyncComputeContacts { + + public static void main(String[] args) throws Exception { + syncComputeContacts(); + } + + public static void syncComputeContacts() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (EssentialContactsServiceClient essentialContactsServiceClient = + EssentialContactsServiceClient.create()) { + ComputeContactsRequest request = + ComputeContactsRequest.newBuilder() + .setParent(ProjectName.of("[PROJECT]").toString()) + .addAllNotificationCategories(new ArrayList()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + for (Contact element : essentialContactsServiceClient.computeContacts(request).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END essentialcontacts_v1_generated_essentialcontactsserviceclient_computecontacts_sync] diff --git a/samples/snippets/generated/com/google/cloud/essentialcontacts/v1/essentialcontactsserviceclient/create/SyncCreateSetCredentialsProvider.java b/samples/snippets/generated/com/google/cloud/essentialcontacts/v1/essentialcontactsserviceclient/create/SyncCreateSetCredentialsProvider.java new file mode 100644 index 00000000..24fbbfaa --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/essentialcontacts/v1/essentialcontactsserviceclient/create/SyncCreateSetCredentialsProvider.java @@ -0,0 +1,44 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.essentialcontacts.v1.samples; + +// [START +// essentialcontacts_v1_generated_essentialcontactsserviceclient_create_setcredentialsprovider_sync] +import com.google.api.gax.core.FixedCredentialsProvider; +import com.google.cloud.essentialcontacts.v1.EssentialContactsServiceClient; +import com.google.cloud.essentialcontacts.v1.EssentialContactsServiceSettings; +import com.google.cloud.essentialcontacts.v1.myCredentials; + +public class SyncCreateSetCredentialsProvider { + + public static void main(String[] args) throws Exception { + syncCreateSetCredentialsProvider(); + } + + public static void syncCreateSetCredentialsProvider() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + EssentialContactsServiceSettings essentialContactsServiceSettings = + EssentialContactsServiceSettings.newBuilder() + .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials)) + .build(); + EssentialContactsServiceClient essentialContactsServiceClient = + EssentialContactsServiceClient.create(essentialContactsServiceSettings); + } +} +// [END +// essentialcontacts_v1_generated_essentialcontactsserviceclient_create_setcredentialsprovider_sync] diff --git a/samples/snippets/generated/com/google/cloud/essentialcontacts/v1/essentialcontactsserviceclient/create/SyncCreateSetCredentialsProvider1.java b/samples/snippets/generated/com/google/cloud/essentialcontacts/v1/essentialcontactsserviceclient/create/SyncCreateSetCredentialsProvider1.java new file mode 100644 index 00000000..2b96d39c --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/essentialcontacts/v1/essentialcontactsserviceclient/create/SyncCreateSetCredentialsProvider1.java @@ -0,0 +1,43 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.essentialcontacts.v1.samples; + +// [START +// essentialcontacts_v1_generated_essentialcontactsserviceclient_create_setcredentialsprovider1_sync] +import com.google.cloud.essentialcontacts.v1.EssentialContactsServiceClient; +import com.google.cloud.essentialcontacts.v1.EssentialContactsServiceSettings; + +public class SyncCreateSetCredentialsProvider1 { + + public static void main(String[] args) throws Exception { + syncCreateSetCredentialsProvider1(); + } + + public static void syncCreateSetCredentialsProvider1() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + EssentialContactsServiceSettings essentialContactsServiceSettings = + EssentialContactsServiceSettings.newBuilder() + .setTransportChannelProvider( + EssentialContactsServiceSettings.defaultHttpJsonTransportProviderBuilder().build()) + .build(); + EssentialContactsServiceClient essentialContactsServiceClient = + EssentialContactsServiceClient.create(essentialContactsServiceSettings); + } +} +// [END +// essentialcontacts_v1_generated_essentialcontactsserviceclient_create_setcredentialsprovider1_sync] diff --git a/samples/snippets/generated/com/google/cloud/essentialcontacts/v1/essentialcontactsserviceclient/create/SyncCreateSetEndpoint.java b/samples/snippets/generated/com/google/cloud/essentialcontacts/v1/essentialcontactsserviceclient/create/SyncCreateSetEndpoint.java new file mode 100644 index 00000000..05091ff9 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/essentialcontacts/v1/essentialcontactsserviceclient/create/SyncCreateSetEndpoint.java @@ -0,0 +1,39 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.essentialcontacts.v1.samples; + +// [START essentialcontacts_v1_generated_essentialcontactsserviceclient_create_setendpoint_sync] +import com.google.cloud.essentialcontacts.v1.EssentialContactsServiceClient; +import com.google.cloud.essentialcontacts.v1.EssentialContactsServiceSettings; +import com.google.cloud.essentialcontacts.v1.myEndpoint; + +public class SyncCreateSetEndpoint { + + public static void main(String[] args) throws Exception { + syncCreateSetEndpoint(); + } + + public static void syncCreateSetEndpoint() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + EssentialContactsServiceSettings essentialContactsServiceSettings = + EssentialContactsServiceSettings.newBuilder().setEndpoint(myEndpoint).build(); + EssentialContactsServiceClient essentialContactsServiceClient = + EssentialContactsServiceClient.create(essentialContactsServiceSettings); + } +} +// [END essentialcontacts_v1_generated_essentialcontactsserviceclient_create_setendpoint_sync] diff --git a/samples/snippets/generated/com/google/cloud/essentialcontacts/v1/essentialcontactsserviceclient/createcontact/AsyncCreateContact.java b/samples/snippets/generated/com/google/cloud/essentialcontacts/v1/essentialcontactsserviceclient/createcontact/AsyncCreateContact.java new file mode 100644 index 00000000..43dd6f65 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/essentialcontacts/v1/essentialcontactsserviceclient/createcontact/AsyncCreateContact.java @@ -0,0 +1,49 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.essentialcontacts.v1.samples; + +// [START essentialcontacts_v1_generated_essentialcontactsserviceclient_createcontact_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.essentialcontacts.v1.Contact; +import com.google.cloud.essentialcontacts.v1.CreateContactRequest; +import com.google.cloud.essentialcontacts.v1.EssentialContactsServiceClient; +import com.google.cloud.essentialcontacts.v1.ProjectName; + +public class AsyncCreateContact { + + public static void main(String[] args) throws Exception { + asyncCreateContact(); + } + + public static void asyncCreateContact() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (EssentialContactsServiceClient essentialContactsServiceClient = + EssentialContactsServiceClient.create()) { + CreateContactRequest request = + CreateContactRequest.newBuilder() + .setParent(ProjectName.of("[PROJECT]").toString()) + .setContact(Contact.newBuilder().build()) + .build(); + ApiFuture future = + essentialContactsServiceClient.createContactCallable().futureCall(request); + // Do something. + Contact response = future.get(); + } + } +} +// [END essentialcontacts_v1_generated_essentialcontactsserviceclient_createcontact_async] diff --git a/samples/snippets/generated/com/google/cloud/essentialcontacts/v1/essentialcontactsserviceclient/createcontact/SyncCreateContact.java b/samples/snippets/generated/com/google/cloud/essentialcontacts/v1/essentialcontactsserviceclient/createcontact/SyncCreateContact.java new file mode 100644 index 00000000..c117c025 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/essentialcontacts/v1/essentialcontactsserviceclient/createcontact/SyncCreateContact.java @@ -0,0 +1,45 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.essentialcontacts.v1.samples; + +// [START essentialcontacts_v1_generated_essentialcontactsserviceclient_createcontact_sync] +import com.google.cloud.essentialcontacts.v1.Contact; +import com.google.cloud.essentialcontacts.v1.CreateContactRequest; +import com.google.cloud.essentialcontacts.v1.EssentialContactsServiceClient; +import com.google.cloud.essentialcontacts.v1.ProjectName; + +public class SyncCreateContact { + + public static void main(String[] args) throws Exception { + syncCreateContact(); + } + + public static void syncCreateContact() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (EssentialContactsServiceClient essentialContactsServiceClient = + EssentialContactsServiceClient.create()) { + CreateContactRequest request = + CreateContactRequest.newBuilder() + .setParent(ProjectName.of("[PROJECT]").toString()) + .setContact(Contact.newBuilder().build()) + .build(); + Contact response = essentialContactsServiceClient.createContact(request); + } + } +} +// [END essentialcontacts_v1_generated_essentialcontactsserviceclient_createcontact_sync] diff --git a/samples/snippets/generated/com/google/cloud/essentialcontacts/v1/essentialcontactsserviceclient/createcontact/SyncCreateContactFoldernameContact.java b/samples/snippets/generated/com/google/cloud/essentialcontacts/v1/essentialcontactsserviceclient/createcontact/SyncCreateContactFoldernameContact.java new file mode 100644 index 00000000..1eb22dcb --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/essentialcontacts/v1/essentialcontactsserviceclient/createcontact/SyncCreateContactFoldernameContact.java @@ -0,0 +1,43 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.essentialcontacts.v1.samples; + +// [START +// essentialcontacts_v1_generated_essentialcontactsserviceclient_createcontact_foldernamecontact_sync] +import com.google.cloud.essentialcontacts.v1.Contact; +import com.google.cloud.essentialcontacts.v1.EssentialContactsServiceClient; +import com.google.cloud.essentialcontacts.v1.FolderName; + +public class SyncCreateContactFoldernameContact { + + public static void main(String[] args) throws Exception { + syncCreateContactFoldernameContact(); + } + + public static void syncCreateContactFoldernameContact() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (EssentialContactsServiceClient essentialContactsServiceClient = + EssentialContactsServiceClient.create()) { + FolderName parent = FolderName.of("[FOLDER]"); + Contact contact = Contact.newBuilder().build(); + Contact response = essentialContactsServiceClient.createContact(parent, contact); + } + } +} +// [END +// essentialcontacts_v1_generated_essentialcontactsserviceclient_createcontact_foldernamecontact_sync] diff --git a/samples/snippets/generated/com/google/cloud/essentialcontacts/v1/essentialcontactsserviceclient/createcontact/SyncCreateContactOrganizationnameContact.java b/samples/snippets/generated/com/google/cloud/essentialcontacts/v1/essentialcontactsserviceclient/createcontact/SyncCreateContactOrganizationnameContact.java new file mode 100644 index 00000000..9abbaa7a --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/essentialcontacts/v1/essentialcontactsserviceclient/createcontact/SyncCreateContactOrganizationnameContact.java @@ -0,0 +1,43 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.essentialcontacts.v1.samples; + +// [START +// essentialcontacts_v1_generated_essentialcontactsserviceclient_createcontact_organizationnamecontact_sync] +import com.google.cloud.essentialcontacts.v1.Contact; +import com.google.cloud.essentialcontacts.v1.EssentialContactsServiceClient; +import com.google.cloud.essentialcontacts.v1.OrganizationName; + +public class SyncCreateContactOrganizationnameContact { + + public static void main(String[] args) throws Exception { + syncCreateContactOrganizationnameContact(); + } + + public static void syncCreateContactOrganizationnameContact() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (EssentialContactsServiceClient essentialContactsServiceClient = + EssentialContactsServiceClient.create()) { + OrganizationName parent = OrganizationName.of("[ORGANIZATION]"); + Contact contact = Contact.newBuilder().build(); + Contact response = essentialContactsServiceClient.createContact(parent, contact); + } + } +} +// [END +// essentialcontacts_v1_generated_essentialcontactsserviceclient_createcontact_organizationnamecontact_sync] diff --git a/samples/snippets/generated/com/google/cloud/essentialcontacts/v1/essentialcontactsserviceclient/createcontact/SyncCreateContactProjectnameContact.java b/samples/snippets/generated/com/google/cloud/essentialcontacts/v1/essentialcontactsserviceclient/createcontact/SyncCreateContactProjectnameContact.java new file mode 100644 index 00000000..dbd48473 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/essentialcontacts/v1/essentialcontactsserviceclient/createcontact/SyncCreateContactProjectnameContact.java @@ -0,0 +1,43 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.essentialcontacts.v1.samples; + +// [START +// essentialcontacts_v1_generated_essentialcontactsserviceclient_createcontact_projectnamecontact_sync] +import com.google.cloud.essentialcontacts.v1.Contact; +import com.google.cloud.essentialcontacts.v1.EssentialContactsServiceClient; +import com.google.cloud.essentialcontacts.v1.ProjectName; + +public class SyncCreateContactProjectnameContact { + + public static void main(String[] args) throws Exception { + syncCreateContactProjectnameContact(); + } + + public static void syncCreateContactProjectnameContact() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (EssentialContactsServiceClient essentialContactsServiceClient = + EssentialContactsServiceClient.create()) { + ProjectName parent = ProjectName.of("[PROJECT]"); + Contact contact = Contact.newBuilder().build(); + Contact response = essentialContactsServiceClient.createContact(parent, contact); + } + } +} +// [END +// essentialcontacts_v1_generated_essentialcontactsserviceclient_createcontact_projectnamecontact_sync] diff --git a/samples/snippets/generated/com/google/cloud/essentialcontacts/v1/essentialcontactsserviceclient/createcontact/SyncCreateContactStringContact.java b/samples/snippets/generated/com/google/cloud/essentialcontacts/v1/essentialcontactsserviceclient/createcontact/SyncCreateContactStringContact.java new file mode 100644 index 00000000..6fe8ca1d --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/essentialcontacts/v1/essentialcontactsserviceclient/createcontact/SyncCreateContactStringContact.java @@ -0,0 +1,43 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.essentialcontacts.v1.samples; + +// [START +// essentialcontacts_v1_generated_essentialcontactsserviceclient_createcontact_stringcontact_sync] +import com.google.cloud.essentialcontacts.v1.Contact; +import com.google.cloud.essentialcontacts.v1.EssentialContactsServiceClient; +import com.google.cloud.essentialcontacts.v1.ProjectName; + +public class SyncCreateContactStringContact { + + public static void main(String[] args) throws Exception { + syncCreateContactStringContact(); + } + + public static void syncCreateContactStringContact() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (EssentialContactsServiceClient essentialContactsServiceClient = + EssentialContactsServiceClient.create()) { + String parent = ProjectName.of("[PROJECT]").toString(); + Contact contact = Contact.newBuilder().build(); + Contact response = essentialContactsServiceClient.createContact(parent, contact); + } + } +} +// [END +// essentialcontacts_v1_generated_essentialcontactsserviceclient_createcontact_stringcontact_sync] diff --git a/samples/snippets/generated/com/google/cloud/essentialcontacts/v1/essentialcontactsserviceclient/deletecontact/AsyncDeleteContact.java b/samples/snippets/generated/com/google/cloud/essentialcontacts/v1/essentialcontactsserviceclient/deletecontact/AsyncDeleteContact.java new file mode 100644 index 00000000..a4a14638 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/essentialcontacts/v1/essentialcontactsserviceclient/deletecontact/AsyncDeleteContact.java @@ -0,0 +1,48 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.essentialcontacts.v1.samples; + +// [START essentialcontacts_v1_generated_essentialcontactsserviceclient_deletecontact_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.essentialcontacts.v1.ContactName; +import com.google.cloud.essentialcontacts.v1.DeleteContactRequest; +import com.google.cloud.essentialcontacts.v1.EssentialContactsServiceClient; +import com.google.protobuf.Empty; + +public class AsyncDeleteContact { + + public static void main(String[] args) throws Exception { + asyncDeleteContact(); + } + + public static void asyncDeleteContact() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (EssentialContactsServiceClient essentialContactsServiceClient = + EssentialContactsServiceClient.create()) { + DeleteContactRequest request = + DeleteContactRequest.newBuilder() + .setName(ContactName.ofProjectContactName("[PROJECT]", "[CONTACT]").toString()) + .build(); + ApiFuture future = + essentialContactsServiceClient.deleteContactCallable().futureCall(request); + // Do something. + future.get(); + } + } +} +// [END essentialcontacts_v1_generated_essentialcontactsserviceclient_deletecontact_async] diff --git a/samples/snippets/generated/com/google/cloud/essentialcontacts/v1/essentialcontactsserviceclient/deletecontact/SyncDeleteContact.java b/samples/snippets/generated/com/google/cloud/essentialcontacts/v1/essentialcontactsserviceclient/deletecontact/SyncDeleteContact.java new file mode 100644 index 00000000..a3f95304 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/essentialcontacts/v1/essentialcontactsserviceclient/deletecontact/SyncDeleteContact.java @@ -0,0 +1,43 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.essentialcontacts.v1.samples; + +// [START essentialcontacts_v1_generated_essentialcontactsserviceclient_deletecontact_sync] +import com.google.cloud.essentialcontacts.v1.ContactName; +import com.google.cloud.essentialcontacts.v1.DeleteContactRequest; +import com.google.cloud.essentialcontacts.v1.EssentialContactsServiceClient; + +public class SyncDeleteContact { + + public static void main(String[] args) throws Exception { + syncDeleteContact(); + } + + public static void syncDeleteContact() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (EssentialContactsServiceClient essentialContactsServiceClient = + EssentialContactsServiceClient.create()) { + DeleteContactRequest request = + DeleteContactRequest.newBuilder() + .setName(ContactName.ofProjectContactName("[PROJECT]", "[CONTACT]").toString()) + .build(); + essentialContactsServiceClient.deleteContact(request); + } + } +} +// [END essentialcontacts_v1_generated_essentialcontactsserviceclient_deletecontact_sync] diff --git a/samples/snippets/generated/com/google/cloud/essentialcontacts/v1/essentialcontactsserviceclient/deletecontact/SyncDeleteContactContactname.java b/samples/snippets/generated/com/google/cloud/essentialcontacts/v1/essentialcontactsserviceclient/deletecontact/SyncDeleteContactContactname.java new file mode 100644 index 00000000..26bd457c --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/essentialcontacts/v1/essentialcontactsserviceclient/deletecontact/SyncDeleteContactContactname.java @@ -0,0 +1,41 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.essentialcontacts.v1.samples; + +// [START +// essentialcontacts_v1_generated_essentialcontactsserviceclient_deletecontact_contactname_sync] +import com.google.cloud.essentialcontacts.v1.ContactName; +import com.google.cloud.essentialcontacts.v1.EssentialContactsServiceClient; + +public class SyncDeleteContactContactname { + + public static void main(String[] args) throws Exception { + syncDeleteContactContactname(); + } + + public static void syncDeleteContactContactname() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (EssentialContactsServiceClient essentialContactsServiceClient = + EssentialContactsServiceClient.create()) { + ContactName name = ContactName.ofProjectContactName("[PROJECT]", "[CONTACT]"); + essentialContactsServiceClient.deleteContact(name); + } + } +} +// [END +// essentialcontacts_v1_generated_essentialcontactsserviceclient_deletecontact_contactname_sync] diff --git a/samples/snippets/generated/com/google/cloud/essentialcontacts/v1/essentialcontactsserviceclient/deletecontact/SyncDeleteContactString.java b/samples/snippets/generated/com/google/cloud/essentialcontacts/v1/essentialcontactsserviceclient/deletecontact/SyncDeleteContactString.java new file mode 100644 index 00000000..22fb3fca --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/essentialcontacts/v1/essentialcontactsserviceclient/deletecontact/SyncDeleteContactString.java @@ -0,0 +1,39 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.essentialcontacts.v1.samples; + +// [START essentialcontacts_v1_generated_essentialcontactsserviceclient_deletecontact_string_sync] +import com.google.cloud.essentialcontacts.v1.ContactName; +import com.google.cloud.essentialcontacts.v1.EssentialContactsServiceClient; + +public class SyncDeleteContactString { + + public static void main(String[] args) throws Exception { + syncDeleteContactString(); + } + + public static void syncDeleteContactString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (EssentialContactsServiceClient essentialContactsServiceClient = + EssentialContactsServiceClient.create()) { + String name = ContactName.ofProjectContactName("[PROJECT]", "[CONTACT]").toString(); + essentialContactsServiceClient.deleteContact(name); + } + } +} +// [END essentialcontacts_v1_generated_essentialcontactsserviceclient_deletecontact_string_sync] diff --git a/samples/snippets/generated/com/google/cloud/essentialcontacts/v1/essentialcontactsserviceclient/getcontact/AsyncGetContact.java b/samples/snippets/generated/com/google/cloud/essentialcontacts/v1/essentialcontactsserviceclient/getcontact/AsyncGetContact.java new file mode 100644 index 00000000..bd801b5b --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/essentialcontacts/v1/essentialcontactsserviceclient/getcontact/AsyncGetContact.java @@ -0,0 +1,48 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.essentialcontacts.v1.samples; + +// [START essentialcontacts_v1_generated_essentialcontactsserviceclient_getcontact_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.essentialcontacts.v1.Contact; +import com.google.cloud.essentialcontacts.v1.ContactName; +import com.google.cloud.essentialcontacts.v1.EssentialContactsServiceClient; +import com.google.cloud.essentialcontacts.v1.GetContactRequest; + +public class AsyncGetContact { + + public static void main(String[] args) throws Exception { + asyncGetContact(); + } + + public static void asyncGetContact() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (EssentialContactsServiceClient essentialContactsServiceClient = + EssentialContactsServiceClient.create()) { + GetContactRequest request = + GetContactRequest.newBuilder() + .setName(ContactName.ofProjectContactName("[PROJECT]", "[CONTACT]").toString()) + .build(); + ApiFuture future = + essentialContactsServiceClient.getContactCallable().futureCall(request); + // Do something. + Contact response = future.get(); + } + } +} +// [END essentialcontacts_v1_generated_essentialcontactsserviceclient_getcontact_async] diff --git a/samples/snippets/generated/com/google/cloud/essentialcontacts/v1/essentialcontactsserviceclient/getcontact/SyncGetContact.java b/samples/snippets/generated/com/google/cloud/essentialcontacts/v1/essentialcontactsserviceclient/getcontact/SyncGetContact.java new file mode 100644 index 00000000..afc62f2c --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/essentialcontacts/v1/essentialcontactsserviceclient/getcontact/SyncGetContact.java @@ -0,0 +1,44 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.essentialcontacts.v1.samples; + +// [START essentialcontacts_v1_generated_essentialcontactsserviceclient_getcontact_sync] +import com.google.cloud.essentialcontacts.v1.Contact; +import com.google.cloud.essentialcontacts.v1.ContactName; +import com.google.cloud.essentialcontacts.v1.EssentialContactsServiceClient; +import com.google.cloud.essentialcontacts.v1.GetContactRequest; + +public class SyncGetContact { + + public static void main(String[] args) throws Exception { + syncGetContact(); + } + + public static void syncGetContact() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (EssentialContactsServiceClient essentialContactsServiceClient = + EssentialContactsServiceClient.create()) { + GetContactRequest request = + GetContactRequest.newBuilder() + .setName(ContactName.ofProjectContactName("[PROJECT]", "[CONTACT]").toString()) + .build(); + Contact response = essentialContactsServiceClient.getContact(request); + } + } +} +// [END essentialcontacts_v1_generated_essentialcontactsserviceclient_getcontact_sync] diff --git a/samples/snippets/generated/com/google/cloud/essentialcontacts/v1/essentialcontactsserviceclient/getcontact/SyncGetContactContactname.java b/samples/snippets/generated/com/google/cloud/essentialcontacts/v1/essentialcontactsserviceclient/getcontact/SyncGetContactContactname.java new file mode 100644 index 00000000..0b90828e --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/essentialcontacts/v1/essentialcontactsserviceclient/getcontact/SyncGetContactContactname.java @@ -0,0 +1,40 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.essentialcontacts.v1.samples; + +// [START essentialcontacts_v1_generated_essentialcontactsserviceclient_getcontact_contactname_sync] +import com.google.cloud.essentialcontacts.v1.Contact; +import com.google.cloud.essentialcontacts.v1.ContactName; +import com.google.cloud.essentialcontacts.v1.EssentialContactsServiceClient; + +public class SyncGetContactContactname { + + public static void main(String[] args) throws Exception { + syncGetContactContactname(); + } + + public static void syncGetContactContactname() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (EssentialContactsServiceClient essentialContactsServiceClient = + EssentialContactsServiceClient.create()) { + ContactName name = ContactName.ofProjectContactName("[PROJECT]", "[CONTACT]"); + Contact response = essentialContactsServiceClient.getContact(name); + } + } +} +// [END essentialcontacts_v1_generated_essentialcontactsserviceclient_getcontact_contactname_sync] diff --git a/samples/snippets/generated/com/google/cloud/essentialcontacts/v1/essentialcontactsserviceclient/getcontact/SyncGetContactString.java b/samples/snippets/generated/com/google/cloud/essentialcontacts/v1/essentialcontactsserviceclient/getcontact/SyncGetContactString.java new file mode 100644 index 00000000..a0bac03b --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/essentialcontacts/v1/essentialcontactsserviceclient/getcontact/SyncGetContactString.java @@ -0,0 +1,40 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.essentialcontacts.v1.samples; + +// [START essentialcontacts_v1_generated_essentialcontactsserviceclient_getcontact_string_sync] +import com.google.cloud.essentialcontacts.v1.Contact; +import com.google.cloud.essentialcontacts.v1.ContactName; +import com.google.cloud.essentialcontacts.v1.EssentialContactsServiceClient; + +public class SyncGetContactString { + + public static void main(String[] args) throws Exception { + syncGetContactString(); + } + + public static void syncGetContactString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (EssentialContactsServiceClient essentialContactsServiceClient = + EssentialContactsServiceClient.create()) { + String name = ContactName.ofProjectContactName("[PROJECT]", "[CONTACT]").toString(); + Contact response = essentialContactsServiceClient.getContact(name); + } + } +} +// [END essentialcontacts_v1_generated_essentialcontactsserviceclient_getcontact_string_sync] diff --git a/samples/snippets/generated/com/google/cloud/essentialcontacts/v1/essentialcontactsserviceclient/listcontacts/AsyncListContacts.java b/samples/snippets/generated/com/google/cloud/essentialcontacts/v1/essentialcontactsserviceclient/listcontacts/AsyncListContacts.java new file mode 100644 index 00000000..9d422ba3 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/essentialcontacts/v1/essentialcontactsserviceclient/listcontacts/AsyncListContacts.java @@ -0,0 +1,52 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.essentialcontacts.v1.samples; + +// [START essentialcontacts_v1_generated_essentialcontactsserviceclient_listcontacts_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.essentialcontacts.v1.Contact; +import com.google.cloud.essentialcontacts.v1.EssentialContactsServiceClient; +import com.google.cloud.essentialcontacts.v1.ListContactsRequest; +import com.google.cloud.essentialcontacts.v1.ProjectName; + +public class AsyncListContacts { + + public static void main(String[] args) throws Exception { + asyncListContacts(); + } + + public static void asyncListContacts() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (EssentialContactsServiceClient essentialContactsServiceClient = + EssentialContactsServiceClient.create()) { + ListContactsRequest request = + ListContactsRequest.newBuilder() + .setParent(ProjectName.of("[PROJECT]").toString()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + ApiFuture future = + essentialContactsServiceClient.listContactsPagedCallable().futureCall(request); + // Do something. + for (Contact element : future.get().iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END essentialcontacts_v1_generated_essentialcontactsserviceclient_listcontacts_async] diff --git a/samples/snippets/generated/com/google/cloud/essentialcontacts/v1/essentialcontactsserviceclient/listcontacts/AsyncListContactsPaged.java b/samples/snippets/generated/com/google/cloud/essentialcontacts/v1/essentialcontactsserviceclient/listcontacts/AsyncListContactsPaged.java new file mode 100644 index 00000000..96bd8003 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/essentialcontacts/v1/essentialcontactsserviceclient/listcontacts/AsyncListContactsPaged.java @@ -0,0 +1,60 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.essentialcontacts.v1.samples; + +// [START essentialcontacts_v1_generated_essentialcontactsserviceclient_listcontacts_paged_async] +import com.google.cloud.essentialcontacts.v1.Contact; +import com.google.cloud.essentialcontacts.v1.EssentialContactsServiceClient; +import com.google.cloud.essentialcontacts.v1.ListContactsRequest; +import com.google.cloud.essentialcontacts.v1.ListContactsResponse; +import com.google.cloud.essentialcontacts.v1.ProjectName; +import com.google.common.base.Strings; + +public class AsyncListContactsPaged { + + public static void main(String[] args) throws Exception { + asyncListContactsPaged(); + } + + public static void asyncListContactsPaged() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (EssentialContactsServiceClient essentialContactsServiceClient = + EssentialContactsServiceClient.create()) { + ListContactsRequest request = + ListContactsRequest.newBuilder() + .setParent(ProjectName.of("[PROJECT]").toString()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + while (true) { + ListContactsResponse response = + essentialContactsServiceClient.listContactsCallable().call(request); + for (Contact element : response.getContactsList()) { + // doThingsWith(element); + } + String nextPageToken = response.getNextPageToken(); + if (!Strings.isNullOrEmpty(nextPageToken)) { + request = request.toBuilder().setPageToken(nextPageToken).build(); + } else { + break; + } + } + } + } +} +// [END essentialcontacts_v1_generated_essentialcontactsserviceclient_listcontacts_paged_async] diff --git a/samples/snippets/generated/com/google/cloud/essentialcontacts/v1/essentialcontactsserviceclient/listcontacts/SyncListContacts.java b/samples/snippets/generated/com/google/cloud/essentialcontacts/v1/essentialcontactsserviceclient/listcontacts/SyncListContacts.java new file mode 100644 index 00000000..a885f025 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/essentialcontacts/v1/essentialcontactsserviceclient/listcontacts/SyncListContacts.java @@ -0,0 +1,48 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.essentialcontacts.v1.samples; + +// [START essentialcontacts_v1_generated_essentialcontactsserviceclient_listcontacts_sync] +import com.google.cloud.essentialcontacts.v1.Contact; +import com.google.cloud.essentialcontacts.v1.EssentialContactsServiceClient; +import com.google.cloud.essentialcontacts.v1.ListContactsRequest; +import com.google.cloud.essentialcontacts.v1.ProjectName; + +public class SyncListContacts { + + public static void main(String[] args) throws Exception { + syncListContacts(); + } + + public static void syncListContacts() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (EssentialContactsServiceClient essentialContactsServiceClient = + EssentialContactsServiceClient.create()) { + ListContactsRequest request = + ListContactsRequest.newBuilder() + .setParent(ProjectName.of("[PROJECT]").toString()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + for (Contact element : essentialContactsServiceClient.listContacts(request).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END essentialcontacts_v1_generated_essentialcontactsserviceclient_listcontacts_sync] diff --git a/samples/snippets/generated/com/google/cloud/essentialcontacts/v1/essentialcontactsserviceclient/listcontacts/SyncListContactsFoldername.java b/samples/snippets/generated/com/google/cloud/essentialcontacts/v1/essentialcontactsserviceclient/listcontacts/SyncListContactsFoldername.java new file mode 100644 index 00000000..77663238 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/essentialcontacts/v1/essentialcontactsserviceclient/listcontacts/SyncListContactsFoldername.java @@ -0,0 +1,43 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.essentialcontacts.v1.samples; + +// [START +// essentialcontacts_v1_generated_essentialcontactsserviceclient_listcontacts_foldername_sync] +import com.google.cloud.essentialcontacts.v1.Contact; +import com.google.cloud.essentialcontacts.v1.EssentialContactsServiceClient; +import com.google.cloud.essentialcontacts.v1.FolderName; + +public class SyncListContactsFoldername { + + public static void main(String[] args) throws Exception { + syncListContactsFoldername(); + } + + public static void syncListContactsFoldername() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (EssentialContactsServiceClient essentialContactsServiceClient = + EssentialContactsServiceClient.create()) { + FolderName parent = FolderName.of("[FOLDER]"); + for (Contact element : essentialContactsServiceClient.listContacts(parent).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END essentialcontacts_v1_generated_essentialcontactsserviceclient_listcontacts_foldername_sync] diff --git a/samples/snippets/generated/com/google/cloud/essentialcontacts/v1/essentialcontactsserviceclient/listcontacts/SyncListContactsOrganizationname.java b/samples/snippets/generated/com/google/cloud/essentialcontacts/v1/essentialcontactsserviceclient/listcontacts/SyncListContactsOrganizationname.java new file mode 100644 index 00000000..6670d744 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/essentialcontacts/v1/essentialcontactsserviceclient/listcontacts/SyncListContactsOrganizationname.java @@ -0,0 +1,44 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.essentialcontacts.v1.samples; + +// [START +// essentialcontacts_v1_generated_essentialcontactsserviceclient_listcontacts_organizationname_sync] +import com.google.cloud.essentialcontacts.v1.Contact; +import com.google.cloud.essentialcontacts.v1.EssentialContactsServiceClient; +import com.google.cloud.essentialcontacts.v1.OrganizationName; + +public class SyncListContactsOrganizationname { + + public static void main(String[] args) throws Exception { + syncListContactsOrganizationname(); + } + + public static void syncListContactsOrganizationname() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (EssentialContactsServiceClient essentialContactsServiceClient = + EssentialContactsServiceClient.create()) { + OrganizationName parent = OrganizationName.of("[ORGANIZATION]"); + for (Contact element : essentialContactsServiceClient.listContacts(parent).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END +// essentialcontacts_v1_generated_essentialcontactsserviceclient_listcontacts_organizationname_sync] diff --git a/samples/snippets/generated/com/google/cloud/essentialcontacts/v1/essentialcontactsserviceclient/listcontacts/SyncListContactsProjectname.java b/samples/snippets/generated/com/google/cloud/essentialcontacts/v1/essentialcontactsserviceclient/listcontacts/SyncListContactsProjectname.java new file mode 100644 index 00000000..54d9051d --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/essentialcontacts/v1/essentialcontactsserviceclient/listcontacts/SyncListContactsProjectname.java @@ -0,0 +1,43 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.essentialcontacts.v1.samples; + +// [START +// essentialcontacts_v1_generated_essentialcontactsserviceclient_listcontacts_projectname_sync] +import com.google.cloud.essentialcontacts.v1.Contact; +import com.google.cloud.essentialcontacts.v1.EssentialContactsServiceClient; +import com.google.cloud.essentialcontacts.v1.ProjectName; + +public class SyncListContactsProjectname { + + public static void main(String[] args) throws Exception { + syncListContactsProjectname(); + } + + public static void syncListContactsProjectname() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (EssentialContactsServiceClient essentialContactsServiceClient = + EssentialContactsServiceClient.create()) { + ProjectName parent = ProjectName.of("[PROJECT]"); + for (Contact element : essentialContactsServiceClient.listContacts(parent).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END essentialcontacts_v1_generated_essentialcontactsserviceclient_listcontacts_projectname_sync] diff --git a/samples/snippets/generated/com/google/cloud/essentialcontacts/v1/essentialcontactsserviceclient/listcontacts/SyncListContactsString.java b/samples/snippets/generated/com/google/cloud/essentialcontacts/v1/essentialcontactsserviceclient/listcontacts/SyncListContactsString.java new file mode 100644 index 00000000..825c237e --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/essentialcontacts/v1/essentialcontactsserviceclient/listcontacts/SyncListContactsString.java @@ -0,0 +1,42 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.essentialcontacts.v1.samples; + +// [START essentialcontacts_v1_generated_essentialcontactsserviceclient_listcontacts_string_sync] +import com.google.cloud.essentialcontacts.v1.Contact; +import com.google.cloud.essentialcontacts.v1.EssentialContactsServiceClient; +import com.google.cloud.essentialcontacts.v1.ProjectName; + +public class SyncListContactsString { + + public static void main(String[] args) throws Exception { + syncListContactsString(); + } + + public static void syncListContactsString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (EssentialContactsServiceClient essentialContactsServiceClient = + EssentialContactsServiceClient.create()) { + String parent = ProjectName.of("[PROJECT]").toString(); + for (Contact element : essentialContactsServiceClient.listContacts(parent).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END essentialcontacts_v1_generated_essentialcontactsserviceclient_listcontacts_string_sync] diff --git a/samples/snippets/generated/com/google/cloud/essentialcontacts/v1/essentialcontactsserviceclient/sendtestmessage/AsyncSendTestMessage.java b/samples/snippets/generated/com/google/cloud/essentialcontacts/v1/essentialcontactsserviceclient/sendtestmessage/AsyncSendTestMessage.java new file mode 100644 index 00000000..7ba269a9 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/essentialcontacts/v1/essentialcontactsserviceclient/sendtestmessage/AsyncSendTestMessage.java @@ -0,0 +1,52 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.essentialcontacts.v1.samples; + +// [START essentialcontacts_v1_generated_essentialcontactsserviceclient_sendtestmessage_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.essentialcontacts.v1.EssentialContactsServiceClient; +import com.google.cloud.essentialcontacts.v1.NotificationCategory; +import com.google.cloud.essentialcontacts.v1.ProjectName; +import com.google.cloud.essentialcontacts.v1.SendTestMessageRequest; +import com.google.protobuf.Empty; +import java.util.ArrayList; + +public class AsyncSendTestMessage { + + public static void main(String[] args) throws Exception { + asyncSendTestMessage(); + } + + public static void asyncSendTestMessage() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (EssentialContactsServiceClient essentialContactsServiceClient = + EssentialContactsServiceClient.create()) { + SendTestMessageRequest request = + SendTestMessageRequest.newBuilder() + .addAllContacts(new ArrayList()) + .setResource(ProjectName.of("[PROJECT]").toString()) + .setNotificationCategory(NotificationCategory.forNumber(0)) + .build(); + ApiFuture future = + essentialContactsServiceClient.sendTestMessageCallable().futureCall(request); + // Do something. + future.get(); + } + } +} +// [END essentialcontacts_v1_generated_essentialcontactsserviceclient_sendtestmessage_async] diff --git a/samples/snippets/generated/com/google/cloud/essentialcontacts/v1/essentialcontactsserviceclient/sendtestmessage/SyncSendTestMessage.java b/samples/snippets/generated/com/google/cloud/essentialcontacts/v1/essentialcontactsserviceclient/sendtestmessage/SyncSendTestMessage.java new file mode 100644 index 00000000..5ce76444 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/essentialcontacts/v1/essentialcontactsserviceclient/sendtestmessage/SyncSendTestMessage.java @@ -0,0 +1,47 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.essentialcontacts.v1.samples; + +// [START essentialcontacts_v1_generated_essentialcontactsserviceclient_sendtestmessage_sync] +import com.google.cloud.essentialcontacts.v1.EssentialContactsServiceClient; +import com.google.cloud.essentialcontacts.v1.NotificationCategory; +import com.google.cloud.essentialcontacts.v1.ProjectName; +import com.google.cloud.essentialcontacts.v1.SendTestMessageRequest; +import java.util.ArrayList; + +public class SyncSendTestMessage { + + public static void main(String[] args) throws Exception { + syncSendTestMessage(); + } + + public static void syncSendTestMessage() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (EssentialContactsServiceClient essentialContactsServiceClient = + EssentialContactsServiceClient.create()) { + SendTestMessageRequest request = + SendTestMessageRequest.newBuilder() + .addAllContacts(new ArrayList()) + .setResource(ProjectName.of("[PROJECT]").toString()) + .setNotificationCategory(NotificationCategory.forNumber(0)) + .build(); + essentialContactsServiceClient.sendTestMessage(request); + } + } +} +// [END essentialcontacts_v1_generated_essentialcontactsserviceclient_sendtestmessage_sync] diff --git a/samples/snippets/generated/com/google/cloud/essentialcontacts/v1/essentialcontactsserviceclient/updatecontact/AsyncUpdateContact.java b/samples/snippets/generated/com/google/cloud/essentialcontacts/v1/essentialcontactsserviceclient/updatecontact/AsyncUpdateContact.java new file mode 100644 index 00000000..8617fff0 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/essentialcontacts/v1/essentialcontactsserviceclient/updatecontact/AsyncUpdateContact.java @@ -0,0 +1,49 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.essentialcontacts.v1.samples; + +// [START essentialcontacts_v1_generated_essentialcontactsserviceclient_updatecontact_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.essentialcontacts.v1.Contact; +import com.google.cloud.essentialcontacts.v1.EssentialContactsServiceClient; +import com.google.cloud.essentialcontacts.v1.UpdateContactRequest; +import com.google.protobuf.FieldMask; + +public class AsyncUpdateContact { + + public static void main(String[] args) throws Exception { + asyncUpdateContact(); + } + + public static void asyncUpdateContact() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (EssentialContactsServiceClient essentialContactsServiceClient = + EssentialContactsServiceClient.create()) { + UpdateContactRequest request = + UpdateContactRequest.newBuilder() + .setContact(Contact.newBuilder().build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .build(); + ApiFuture future = + essentialContactsServiceClient.updateContactCallable().futureCall(request); + // Do something. + Contact response = future.get(); + } + } +} +// [END essentialcontacts_v1_generated_essentialcontactsserviceclient_updatecontact_async] diff --git a/samples/snippets/generated/com/google/cloud/essentialcontacts/v1/essentialcontactsserviceclient/updatecontact/SyncUpdateContact.java b/samples/snippets/generated/com/google/cloud/essentialcontacts/v1/essentialcontactsserviceclient/updatecontact/SyncUpdateContact.java new file mode 100644 index 00000000..d2102a09 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/essentialcontacts/v1/essentialcontactsserviceclient/updatecontact/SyncUpdateContact.java @@ -0,0 +1,45 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.essentialcontacts.v1.samples; + +// [START essentialcontacts_v1_generated_essentialcontactsserviceclient_updatecontact_sync] +import com.google.cloud.essentialcontacts.v1.Contact; +import com.google.cloud.essentialcontacts.v1.EssentialContactsServiceClient; +import com.google.cloud.essentialcontacts.v1.UpdateContactRequest; +import com.google.protobuf.FieldMask; + +public class SyncUpdateContact { + + public static void main(String[] args) throws Exception { + syncUpdateContact(); + } + + public static void syncUpdateContact() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (EssentialContactsServiceClient essentialContactsServiceClient = + EssentialContactsServiceClient.create()) { + UpdateContactRequest request = + UpdateContactRequest.newBuilder() + .setContact(Contact.newBuilder().build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .build(); + Contact response = essentialContactsServiceClient.updateContact(request); + } + } +} +// [END essentialcontacts_v1_generated_essentialcontactsserviceclient_updatecontact_sync] diff --git a/samples/snippets/generated/com/google/cloud/essentialcontacts/v1/essentialcontactsserviceclient/updatecontact/SyncUpdateContactContactFieldmask.java b/samples/snippets/generated/com/google/cloud/essentialcontacts/v1/essentialcontactsserviceclient/updatecontact/SyncUpdateContactContactFieldmask.java new file mode 100644 index 00000000..27ca6e5e --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/essentialcontacts/v1/essentialcontactsserviceclient/updatecontact/SyncUpdateContactContactFieldmask.java @@ -0,0 +1,43 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.essentialcontacts.v1.samples; + +// [START +// essentialcontacts_v1_generated_essentialcontactsserviceclient_updatecontact_contactfieldmask_sync] +import com.google.cloud.essentialcontacts.v1.Contact; +import com.google.cloud.essentialcontacts.v1.EssentialContactsServiceClient; +import com.google.protobuf.FieldMask; + +public class SyncUpdateContactContactFieldmask { + + public static void main(String[] args) throws Exception { + syncUpdateContactContactFieldmask(); + } + + public static void syncUpdateContactContactFieldmask() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (EssentialContactsServiceClient essentialContactsServiceClient = + EssentialContactsServiceClient.create()) { + Contact contact = Contact.newBuilder().build(); + FieldMask updateMask = FieldMask.newBuilder().build(); + Contact response = essentialContactsServiceClient.updateContact(contact, updateMask); + } + } +} +// [END +// essentialcontacts_v1_generated_essentialcontactsserviceclient_updatecontact_contactfieldmask_sync] diff --git a/samples/snippets/generated/com/google/cloud/essentialcontacts/v1/essentialcontactsservicesettings/createcontact/SyncCreateContact.java b/samples/snippets/generated/com/google/cloud/essentialcontacts/v1/essentialcontactsservicesettings/createcontact/SyncCreateContact.java new file mode 100644 index 00000000..55e546db --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/essentialcontacts/v1/essentialcontactsservicesettings/createcontact/SyncCreateContact.java @@ -0,0 +1,47 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.essentialcontacts.v1.samples; + +// [START essentialcontacts_v1_generated_essentialcontactsservicesettings_createcontact_sync] +import com.google.cloud.essentialcontacts.v1.EssentialContactsServiceSettings; +import java.time.Duration; + +public class SyncCreateContact { + + public static void main(String[] args) throws Exception { + syncCreateContact(); + } + + public static void syncCreateContact() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + EssentialContactsServiceSettings.Builder essentialContactsServiceSettingsBuilder = + EssentialContactsServiceSettings.newBuilder(); + essentialContactsServiceSettingsBuilder + .createContactSettings() + .setRetrySettings( + essentialContactsServiceSettingsBuilder + .createContactSettings() + .getRetrySettings() + .toBuilder() + .setTotalTimeout(Duration.ofSeconds(30)) + .build()); + EssentialContactsServiceSettings essentialContactsServiceSettings = + essentialContactsServiceSettingsBuilder.build(); + } +} +// [END essentialcontacts_v1_generated_essentialcontactsservicesettings_createcontact_sync] diff --git a/samples/snippets/generated/com/google/cloud/essentialcontacts/v1/stub/essentialcontactsservicestubsettings/createcontact/SyncCreateContact.java b/samples/snippets/generated/com/google/cloud/essentialcontacts/v1/stub/essentialcontactsservicestubsettings/createcontact/SyncCreateContact.java new file mode 100644 index 00000000..41154f72 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/essentialcontacts/v1/stub/essentialcontactsservicestubsettings/createcontact/SyncCreateContact.java @@ -0,0 +1,47 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.essentialcontacts.v1.stub.samples; + +// [START essentialcontacts_v1_generated_essentialcontactsservicestubsettings_createcontact_sync] +import com.google.cloud.essentialcontacts.v1.stub.EssentialContactsServiceStubSettings; +import java.time.Duration; + +public class SyncCreateContact { + + public static void main(String[] args) throws Exception { + syncCreateContact(); + } + + public static void syncCreateContact() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + EssentialContactsServiceStubSettings.Builder essentialContactsServiceSettingsBuilder = + EssentialContactsServiceStubSettings.newBuilder(); + essentialContactsServiceSettingsBuilder + .createContactSettings() + .setRetrySettings( + essentialContactsServiceSettingsBuilder + .createContactSettings() + .getRetrySettings() + .toBuilder() + .setTotalTimeout(Duration.ofSeconds(30)) + .build()); + EssentialContactsServiceStubSettings essentialContactsServiceSettings = + essentialContactsServiceSettingsBuilder.build(); + } +} +// [END essentialcontacts_v1_generated_essentialcontactsservicestubsettings_createcontact_sync]