1 // Copyright 2018 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include "google/cloud/bigtable/app_profile_config.h"
16 
17 namespace google {
18 namespace cloud {
19 namespace bigtable {
20 inline namespace BIGTABLE_CLIENT_NS {
MultiClusterUseAny(std::string profile_id)21 AppProfileConfig AppProfileConfig::MultiClusterUseAny(std::string profile_id) {
22   AppProfileConfig tmp;
23   tmp.proto_.set_app_profile_id(std::move(profile_id));
24   tmp.proto_.mutable_app_profile()
25       ->mutable_multi_cluster_routing_use_any()
26       ->Clear();
27   return tmp;
28 }
29 
SingleClusterRouting(std::string profile_id,std::string cluster_id,bool allow_transactional_writes)30 AppProfileConfig AppProfileConfig::SingleClusterRouting(
31     std::string profile_id, std::string cluster_id,
32     bool allow_transactional_writes) {
33   AppProfileConfig tmp;
34   tmp.proto_.set_app_profile_id(std::move(profile_id));
35   auto& routing =
36       *tmp.proto_.mutable_app_profile()->mutable_single_cluster_routing();
37   routing.set_cluster_id(std::move(cluster_id));
38   routing.set_allow_transactional_writes(allow_transactional_writes);
39   return tmp;
40 }
41 
AddPathIfNotPresent(std::string field_name)42 void AppProfileUpdateConfig::AddPathIfNotPresent(std::string field_name) {
43   auto const& paths = proto_.update_mask().paths();
44   auto is_present =
45       paths.end() != std::find(paths.begin(), paths.end(), field_name);
46   if (!is_present) {
47     proto_.mutable_update_mask()->add_paths(std::move(field_name));
48   }
49 }
50 
RemoveIfPresent(std::string const & field_name)51 void AppProfileUpdateConfig::RemoveIfPresent(std::string const& field_name) {
52   auto& paths = *proto_.mutable_update_mask()->mutable_paths();
53   auto i = std::find(paths.begin(), paths.end(), field_name);
54   if (paths.end() == i) {
55     return;
56   }
57   paths.erase(i);
58 }
59 
60 }  // namespace BIGTABLE_CLIENT_NS
61 }  // namespace bigtable
62 }  // namespace cloud
63 }  // namespace google
64