Skip to content
This repository has been archived by the owner on Jul 17, 2023. It is now read-only.

feat: Add ability to update phrase matchers #128

Merged
merged 2 commits into from
Nov 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2946,6 +2946,87 @@ public final UnaryCallable<DeletePhraseMatcherRequest, Empty> deletePhraseMatche
return stub.deletePhraseMatcherCallable();
}

// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
* Updates a phrase matcher.
*
* <p>Sample code:
*
* <pre>{@code
* try (ContactCenterInsightsClient contactCenterInsightsClient =
* ContactCenterInsightsClient.create()) {
* PhraseMatcher phraseMatcher = PhraseMatcher.newBuilder().build();
* FieldMask updateMask = FieldMask.newBuilder().build();
* PhraseMatcher response =
* contactCenterInsightsClient.updatePhraseMatcher(phraseMatcher, updateMask);
* }
* }</pre>
*
* @param phraseMatcher Required. The new values for the phrase matcher.
* @param updateMask The list of fields to be updated.
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
*/
public final PhraseMatcher updatePhraseMatcher(
PhraseMatcher phraseMatcher, FieldMask updateMask) {
UpdatePhraseMatcherRequest request =
UpdatePhraseMatcherRequest.newBuilder()
.setPhraseMatcher(phraseMatcher)
.setUpdateMask(updateMask)
.build();
return updatePhraseMatcher(request);
}

// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
* Updates a phrase matcher.
*
* <p>Sample code:
*
* <pre>{@code
* try (ContactCenterInsightsClient contactCenterInsightsClient =
* ContactCenterInsightsClient.create()) {
* UpdatePhraseMatcherRequest request =
* UpdatePhraseMatcherRequest.newBuilder()
* .setPhraseMatcher(PhraseMatcher.newBuilder().build())
* .setUpdateMask(FieldMask.newBuilder().build())
* .build();
* PhraseMatcher response = contactCenterInsightsClient.updatePhraseMatcher(request);
* }
* }</pre>
*
* @param request The request object containing all of the parameters for the API call.
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
*/
public final PhraseMatcher updatePhraseMatcher(UpdatePhraseMatcherRequest request) {
return updatePhraseMatcherCallable().call(request);
}

// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
* Updates a phrase matcher.
*
* <p>Sample code:
*
* <pre>{@code
* try (ContactCenterInsightsClient contactCenterInsightsClient =
* ContactCenterInsightsClient.create()) {
* UpdatePhraseMatcherRequest request =
* UpdatePhraseMatcherRequest.newBuilder()
* .setPhraseMatcher(PhraseMatcher.newBuilder().build())
* .setUpdateMask(FieldMask.newBuilder().build())
* .build();
* ApiFuture<PhraseMatcher> future =
* contactCenterInsightsClient.updatePhraseMatcherCallable().futureCall(request);
* // Do something.
* PhraseMatcher response = future.get();
* }
* }</pre>
*/
public final UnaryCallable<UpdatePhraseMatcherRequest, PhraseMatcher>
updatePhraseMatcherCallable() {
return stub.updatePhraseMatcherCallable();
}

// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
* Gets conversation statistics.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,12 @@ public UnaryCallSettings<DeletePhraseMatcherRequest, Empty> deletePhraseMatcherS
return ((ContactCenterInsightsStubSettings) getStubSettings()).deletePhraseMatcherSettings();
}

/** Returns the object with the settings used for calls to updatePhraseMatcher. */
public UnaryCallSettings<UpdatePhraseMatcherRequest, PhraseMatcher>
updatePhraseMatcherSettings() {
return ((ContactCenterInsightsStubSettings) getStubSettings()).updatePhraseMatcherSettings();
}

/** Returns the object with the settings used for calls to calculateStats. */
public UnaryCallSettings<CalculateStatsRequest, CalculateStatsResponse> calculateStatsSettings() {
return ((ContactCenterInsightsStubSettings) getStubSettings()).calculateStatsSettings();
Expand Down Expand Up @@ -556,6 +562,12 @@ public UnaryCallSettings.Builder<UpdateIssueRequest, Issue> updateIssueSettings(
return getStubSettingsBuilder().deletePhraseMatcherSettings();
}

/** Returns the builder for the settings used for calls to updatePhraseMatcher. */
public UnaryCallSettings.Builder<UpdatePhraseMatcherRequest, PhraseMatcher>
updatePhraseMatcherSettings() {
return getStubSettingsBuilder().updatePhraseMatcherSettings();
}

/** Returns the builder for the settings used for calls to calculateStats. */
public UnaryCallSettings.Builder<CalculateStatsRequest, CalculateStatsResponse>
calculateStatsSettings() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@
"UpdateIssueModel": {
"methods": ["updateIssueModel", "updateIssueModel", "updateIssueModelCallable"]
},
"UpdatePhraseMatcher": {
"methods": ["updatePhraseMatcher", "updatePhraseMatcher", "updatePhraseMatcherCallable"]
},
"UpdateSettings": {
"methods": ["updateSettings", "updateSettings", "updateSettingsCallable"]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
import com.google.cloud.contactcenterinsights.v1.UpdateConversationRequest;
import com.google.cloud.contactcenterinsights.v1.UpdateIssueModelRequest;
import com.google.cloud.contactcenterinsights.v1.UpdateIssueRequest;
import com.google.cloud.contactcenterinsights.v1.UpdatePhraseMatcherRequest;
import com.google.cloud.contactcenterinsights.v1.UpdateSettingsRequest;
import com.google.longrunning.Operation;
import com.google.longrunning.stub.OperationsStub;
Expand Down Expand Up @@ -243,6 +244,10 @@ public UnaryCallable<DeletePhraseMatcherRequest, Empty> deletePhraseMatcherCalla
throw new UnsupportedOperationException("Not implemented: deletePhraseMatcherCallable()");
}

public UnaryCallable<UpdatePhraseMatcherRequest, PhraseMatcher> updatePhraseMatcherCallable() {
throw new UnsupportedOperationException("Not implemented: updatePhraseMatcherCallable()");
}

public UnaryCallable<CalculateStatsRequest, CalculateStatsResponse> calculateStatsCallable() {
throw new UnsupportedOperationException("Not implemented: calculateStatsCallable()");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
import com.google.cloud.contactcenterinsights.v1.UpdateConversationRequest;
import com.google.cloud.contactcenterinsights.v1.UpdateIssueModelRequest;
import com.google.cloud.contactcenterinsights.v1.UpdateIssueRequest;
import com.google.cloud.contactcenterinsights.v1.UpdatePhraseMatcherRequest;
import com.google.cloud.contactcenterinsights.v1.UpdateSettingsRequest;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
Expand Down Expand Up @@ -200,6 +201,8 @@ public class ContactCenterInsightsStubSettings
ListPhraseMatchersRequest, ListPhraseMatchersResponse, ListPhraseMatchersPagedResponse>
listPhraseMatchersSettings;
private final UnaryCallSettings<DeletePhraseMatcherRequest, Empty> deletePhraseMatcherSettings;
private final UnaryCallSettings<UpdatePhraseMatcherRequest, PhraseMatcher>
updatePhraseMatcherSettings;
private final UnaryCallSettings<CalculateStatsRequest, CalculateStatsResponse>
calculateStatsSettings;
private final UnaryCallSettings<GetSettingsRequest, Settings> getSettingsSettings;
Expand Down Expand Up @@ -552,6 +555,12 @@ public UnaryCallSettings<DeletePhraseMatcherRequest, Empty> deletePhraseMatcherS
return deletePhraseMatcherSettings;
}

/** Returns the object with the settings used for calls to updatePhraseMatcher. */
public UnaryCallSettings<UpdatePhraseMatcherRequest, PhraseMatcher>
updatePhraseMatcherSettings() {
return updatePhraseMatcherSettings;
}

/** Returns the object with the settings used for calls to calculateStats. */
public UnaryCallSettings<CalculateStatsRequest, CalculateStatsResponse> calculateStatsSettings() {
return calculateStatsSettings;
Expand Down Expand Up @@ -676,6 +685,7 @@ protected ContactCenterInsightsStubSettings(Builder settingsBuilder) throws IOEx
getPhraseMatcherSettings = settingsBuilder.getPhraseMatcherSettings().build();
listPhraseMatchersSettings = settingsBuilder.listPhraseMatchersSettings().build();
deletePhraseMatcherSettings = settingsBuilder.deletePhraseMatcherSettings().build();
updatePhraseMatcherSettings = settingsBuilder.updatePhraseMatcherSettings().build();
calculateStatsSettings = settingsBuilder.calculateStatsSettings().build();
getSettingsSettings = settingsBuilder.getSettingsSettings().build();
updateSettingsSettings = settingsBuilder.updateSettingsSettings().build();
Expand Down Expand Up @@ -752,6 +762,8 @@ public static class Builder
listPhraseMatchersSettings;
private final UnaryCallSettings.Builder<DeletePhraseMatcherRequest, Empty>
deletePhraseMatcherSettings;
private final UnaryCallSettings.Builder<UpdatePhraseMatcherRequest, PhraseMatcher>
updatePhraseMatcherSettings;
private final UnaryCallSettings.Builder<CalculateStatsRequest, CalculateStatsResponse>
calculateStatsSettings;
private final UnaryCallSettings.Builder<GetSettingsRequest, Settings> getSettingsSettings;
Expand Down Expand Up @@ -825,6 +837,7 @@ protected Builder(ClientContext clientContext) {
getPhraseMatcherSettings = UnaryCallSettings.newUnaryCallSettingsBuilder();
listPhraseMatchersSettings = PagedCallSettings.newBuilder(LIST_PHRASE_MATCHERS_PAGE_STR_FACT);
deletePhraseMatcherSettings = UnaryCallSettings.newUnaryCallSettingsBuilder();
updatePhraseMatcherSettings = UnaryCallSettings.newUnaryCallSettingsBuilder();
calculateStatsSettings = UnaryCallSettings.newUnaryCallSettingsBuilder();
getSettingsSettings = UnaryCallSettings.newUnaryCallSettingsBuilder();
updateSettingsSettings = UnaryCallSettings.newUnaryCallSettingsBuilder();
Expand Down Expand Up @@ -856,6 +869,7 @@ protected Builder(ClientContext clientContext) {
getPhraseMatcherSettings,
listPhraseMatchersSettings,
deletePhraseMatcherSettings,
updatePhraseMatcherSettings,
calculateStatsSettings,
getSettingsSettings,
updateSettingsSettings);
Expand Down Expand Up @@ -898,6 +912,7 @@ protected Builder(ContactCenterInsightsStubSettings settings) {
getPhraseMatcherSettings = settings.getPhraseMatcherSettings.toBuilder();
listPhraseMatchersSettings = settings.listPhraseMatchersSettings.toBuilder();
deletePhraseMatcherSettings = settings.deletePhraseMatcherSettings.toBuilder();
updatePhraseMatcherSettings = settings.updatePhraseMatcherSettings.toBuilder();
calculateStatsSettings = settings.calculateStatsSettings.toBuilder();
getSettingsSettings = settings.getSettingsSettings.toBuilder();
updateSettingsSettings = settings.updateSettingsSettings.toBuilder();
Expand Down Expand Up @@ -929,6 +944,7 @@ protected Builder(ContactCenterInsightsStubSettings settings) {
getPhraseMatcherSettings,
listPhraseMatchersSettings,
deletePhraseMatcherSettings,
updatePhraseMatcherSettings,
calculateStatsSettings,
getSettingsSettings,
updateSettingsSettings);
Expand Down Expand Up @@ -1073,6 +1089,11 @@ private static Builder initDefaults(Builder builder) {
.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("retry_policy_0_codes"))
.setRetrySettings(RETRY_PARAM_DEFINITIONS.get("retry_policy_0_params"));

builder
.updatePhraseMatcherSettings()
.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("retry_policy_0_codes"))
.setRetrySettings(RETRY_PARAM_DEFINITIONS.get("retry_policy_0_params"));

builder
.calculateStatsSettings()
.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("retry_policy_0_codes"))
Expand Down Expand Up @@ -1455,6 +1476,12 @@ public UnaryCallSettings.Builder<UpdateIssueRequest, Issue> updateIssueSettings(
return deletePhraseMatcherSettings;
}

/** Returns the builder for the settings used for calls to updatePhraseMatcher. */
public UnaryCallSettings.Builder<UpdatePhraseMatcherRequest, PhraseMatcher>
updatePhraseMatcherSettings() {
return updatePhraseMatcherSettings;
}

/** Returns the builder for the settings used for calls to calculateStats. */
public UnaryCallSettings.Builder<CalculateStatsRequest, CalculateStatsResponse>
calculateStatsSettings() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
import com.google.cloud.contactcenterinsights.v1.UpdateConversationRequest;
import com.google.cloud.contactcenterinsights.v1.UpdateIssueModelRequest;
import com.google.cloud.contactcenterinsights.v1.UpdateIssueRequest;
import com.google.cloud.contactcenterinsights.v1.UpdatePhraseMatcherRequest;
import com.google.cloud.contactcenterinsights.v1.UpdateSettingsRequest;
import com.google.common.collect.ImmutableMap;
import com.google.longrunning.Operation;
Expand Down Expand Up @@ -368,6 +369,17 @@ public class GrpcContactCenterInsightsStub extends ContactCenterInsightsStub {
.setResponseMarshaller(ProtoUtils.marshaller(Empty.getDefaultInstance()))
.build();

private static final MethodDescriptor<UpdatePhraseMatcherRequest, PhraseMatcher>
updatePhraseMatcherMethodDescriptor =
MethodDescriptor.<UpdatePhraseMatcherRequest, PhraseMatcher>newBuilder()
.setType(MethodDescriptor.MethodType.UNARY)
.setFullMethodName(
"google.cloud.contactcenterinsights.v1.ContactCenterInsights/UpdatePhraseMatcher")
.setRequestMarshaller(
ProtoUtils.marshaller(UpdatePhraseMatcherRequest.getDefaultInstance()))
.setResponseMarshaller(ProtoUtils.marshaller(PhraseMatcher.getDefaultInstance()))
.build();

private static final MethodDescriptor<CalculateStatsRequest, CalculateStatsResponse>
calculateStatsMethodDescriptor =
MethodDescriptor.<CalculateStatsRequest, CalculateStatsResponse>newBuilder()
Expand Down Expand Up @@ -451,6 +463,8 @@ public class GrpcContactCenterInsightsStub extends ContactCenterInsightsStub {
private final UnaryCallable<ListPhraseMatchersRequest, ListPhraseMatchersPagedResponse>
listPhraseMatchersPagedCallable;
private final UnaryCallable<DeletePhraseMatcherRequest, Empty> deletePhraseMatcherCallable;
private final UnaryCallable<UpdatePhraseMatcherRequest, PhraseMatcher>
updatePhraseMatcherCallable;
private final UnaryCallable<CalculateStatsRequest, CalculateStatsResponse> calculateStatsCallable;
private final UnaryCallable<GetSettingsRequest, Settings> getSettingsCallable;
private final UnaryCallable<UpdateSettingsRequest, Settings> updateSettingsCallable;
Expand Down Expand Up @@ -756,6 +770,19 @@ protected GrpcContactCenterInsightsStub(
return params.build();
})
.build();
GrpcCallSettings<UpdatePhraseMatcherRequest, PhraseMatcher>
updatePhraseMatcherTransportSettings =
GrpcCallSettings.<UpdatePhraseMatcherRequest, PhraseMatcher>newBuilder()
.setMethodDescriptor(updatePhraseMatcherMethodDescriptor)
.setParamsExtractor(
request -> {
ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
params.put(
"phrase_matcher.name",
String.valueOf(request.getPhraseMatcher().getName()));
return params.build();
})
.build();
GrpcCallSettings<CalculateStatsRequest, CalculateStatsResponse>
calculateStatsTransportSettings =
GrpcCallSettings.<CalculateStatsRequest, CalculateStatsResponse>newBuilder()
Expand Down Expand Up @@ -932,6 +959,11 @@ protected GrpcContactCenterInsightsStub(
deletePhraseMatcherTransportSettings,
settings.deletePhraseMatcherSettings(),
clientContext);
this.updatePhraseMatcherCallable =
callableFactory.createUnaryCallable(
updatePhraseMatcherTransportSettings,
settings.updatePhraseMatcherSettings(),
clientContext);
this.calculateStatsCallable =
callableFactory.createUnaryCallable(
calculateStatsTransportSettings, settings.calculateStatsSettings(), clientContext);
Expand Down Expand Up @@ -1134,6 +1166,11 @@ public UnaryCallable<DeletePhraseMatcherRequest, Empty> deletePhraseMatcherCalla
return deletePhraseMatcherCallable;
}

@Override
public UnaryCallable<UpdatePhraseMatcherRequest, PhraseMatcher> updatePhraseMatcherCallable() {
return updatePhraseMatcherCallable;
}

@Override
public UnaryCallable<CalculateStatsRequest, CalculateStatsResponse> calculateStatsCallable() {
return calculateStatsCallable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2145,6 +2145,55 @@ public void deletePhraseMatcherExceptionTest2() throws Exception {
}
}

@Test
public void updatePhraseMatcherTest() throws Exception {
PhraseMatcher expectedResponse =
PhraseMatcher.newBuilder()
.setName(PhraseMatcherName.of("[PROJECT]", "[LOCATION]", "[PHRASE_MATCHER]").toString())
.setRevisionId("revisionId-1507445162")
.setVersionTag("versionTag-670508126")
.setRevisionCreateTime(Timestamp.newBuilder().build())
.setDisplayName("displayName1714148973")
.setActive(true)
.addAllPhraseMatchRuleGroups(new ArrayList<PhraseMatchRuleGroup>())
.setActivationUpdateTime(Timestamp.newBuilder().build())
.setUpdateTime(Timestamp.newBuilder().build())
.build();
mockContactCenterInsights.addResponse(expectedResponse);

PhraseMatcher phraseMatcher = PhraseMatcher.newBuilder().build();
FieldMask updateMask = FieldMask.newBuilder().build();

PhraseMatcher actualResponse = client.updatePhraseMatcher(phraseMatcher, updateMask);
Assert.assertEquals(expectedResponse, actualResponse);

List<AbstractMessage> actualRequests = mockContactCenterInsights.getRequests();
Assert.assertEquals(1, actualRequests.size());
UpdatePhraseMatcherRequest actualRequest = ((UpdatePhraseMatcherRequest) actualRequests.get(0));

Assert.assertEquals(phraseMatcher, actualRequest.getPhraseMatcher());
Assert.assertEquals(updateMask, actualRequest.getUpdateMask());
Assert.assertTrue(
channelProvider.isHeaderSent(
ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}

@Test
public void updatePhraseMatcherExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
mockContactCenterInsights.addException(exception);

try {
PhraseMatcher phraseMatcher = PhraseMatcher.newBuilder().build();
FieldMask updateMask = FieldMask.newBuilder().build();
client.updatePhraseMatcher(phraseMatcher, updateMask);
Assert.fail("No exception raised");
} catch (InvalidArgumentException e) {
// Expected exception.
}
}

@Test
public void calculateStatsTest() throws Exception {
CalculateStatsResponse expectedResponse =
Expand All @@ -2155,6 +2204,7 @@ public void calculateStatsTest() throws Exception {
.putAllSmartHighlighterMatches(new HashMap<String, Integer>())
.putAllCustomHighlighterMatches(new HashMap<String, Integer>())
.putAllIssueMatches(new HashMap<String, Integer>())
.putAllIssueMatchesStats(new HashMap<String, IssueModelLabelStats.IssueStats>())
.setConversationCountTimeSeries(CalculateStatsResponse.TimeSeries.newBuilder().build())
.build();
mockContactCenterInsights.addResponse(expectedResponse);
Expand Down Expand Up @@ -2199,6 +2249,7 @@ public void calculateStatsTest2() throws Exception {
.putAllSmartHighlighterMatches(new HashMap<String, Integer>())
.putAllCustomHighlighterMatches(new HashMap<String, Integer>())
.putAllIssueMatches(new HashMap<String, Integer>())
.putAllIssueMatchesStats(new HashMap<String, IssueModelLabelStats.IssueStats>())
.setConversationCountTimeSeries(CalculateStatsResponse.TimeSeries.newBuilder().build())
.build();
mockContactCenterInsights.addResponse(expectedResponse);
Expand Down
Loading