olp-cpp-sdk  1.22.0
PartitionsRequest.h
1 /*
2  * Copyright (C) 2019-2020 HERE Europe B.V.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  * SPDX-License-Identifier: Apache-2.0
17  * License-Filename: LICENSE
18  */
19 
20 #pragma once
21 
22 #include <sstream>
23 #include <string>
24 #include <utility>
25 #include <vector>
26 
27 #include <olp/core/porting/deprecated.h>
28 #include <olp/dataservice/read/DataServiceReadApi.h>
29 #include <olp/dataservice/read/FetchOptions.h>
30 #include <boost/optional.hpp>
31 
32 namespace olp {
33 namespace dataservice {
34 namespace read {
35 
40 class DATASERVICE_READ_API PartitionsRequest final {
41  public:
43  using PartitionIds = std::vector<std::string>;
44 
46  static constexpr const char* kDataSize = "dataSize";
47 
49  static constexpr const char* kChecksum = "checksum";
50 
53  static constexpr const char* kCompressedDataSize = "compressedDataSize";
54 
56  static constexpr const char* kCrc = "crc";
57 
59  using AdditionalFields = std::vector<std::string>;
60 
73  partition_ids_ = std::move(partition_ids);
74  return *this;
75  }
76 
82  inline const PartitionIds& GetPartitionIds() const { return partition_ids_; }
83 
99  AdditionalFields additional_fields) {
100  additional_fields_ = std::move(additional_fields);
101  return *this;
102  }
103 
109  inline const AdditionalFields& GetAdditionalFields() const {
110  return additional_fields_;
111  }
112 
123  inline const boost::optional<std::string>& GetBillingTag() const {
124  return billing_tag_;
125  }
126 
137  boost::optional<std::string> billingTag) {
138  billing_tag_ = std::move(billingTag);
139  return *this;
140  }
141 
152  inline PartitionsRequest& WithBillingTag(std::string&& billingTag) {
153  billing_tag_ = std::move(billingTag);
154  return *this;
155  }
156 
165  inline FetchOptions GetFetchOption() const { return fetch_option_; }
166 
177  inline PartitionsRequest& WithFetchOption(FetchOptions fetch_option) {
178  fetch_option_ = fetch_option;
179  return *this;
180  }
181 
190  std::string CreateKey(const std::string& layer_id,
191  boost::optional<int64_t> version = boost::none) const {
192  std::stringstream out;
193  out << layer_id;
194  if (version) {
195  out << "@" << version.get();
196  }
197  if (GetBillingTag()) {
198  out << "$" << GetBillingTag().get();
199  }
200  out << "^" << GetFetchOption();
201  return out.str();
202  }
203 
204  private:
205  PartitionIds partition_ids_;
206  AdditionalFields additional_fields_;
207  boost::optional<std::string> billing_tag_;
208  FetchOptions fetch_option_{OnlineIfNotFound};
209 };
210 
211 } // namespace read
212 } // namespace dataservice
213 } // namespace olp
Encapsulates the fields required to request a list of partitions for the given catalog and layer.
Definition: PartitionsRequest.h:40
const boost::optional< std::string > & GetBillingTag() const
Gets the billing tag to group billing records together.
Definition: PartitionsRequest.h:123
PartitionsRequest & WithBillingTag(boost::optional< std::string > billingTag)
Sets the billing tag for the request.
Definition: PartitionsRequest.h:136
std::vector< std::string > AdditionalFields
An alias for the set of additional fields.
Definition: PartitionsRequest.h:59
const PartitionIds & GetPartitionIds() const
Gets the list of the partitions.
Definition: PartitionsRequest.h:82
PartitionsRequest & WithPartitionIds(PartitionIds partition_ids)
Sets the list of partitions.
Definition: PartitionsRequest.h:72
std::vector< std::string > PartitionIds
An alias for the vector of partitions IDs.
Definition: PartitionsRequest.h:43
std::string CreateKey(const std::string &layer_id, boost::optional< int64_t > version=boost::none) const
Creates a readable format for the request.
Definition: PartitionsRequest.h:190
const AdditionalFields & GetAdditionalFields() const
Gets the list of additional fields.
Definition: PartitionsRequest.h:109
PartitionsRequest & WithBillingTag(std::string &&billingTag)
Sets the billing tag for the request.
Definition: PartitionsRequest.h:152
PartitionsRequest & WithFetchOption(FetchOptions fetch_option)
Sets the fetch option that you can use to set the source from which data should be fetched.
Definition: PartitionsRequest.h:177
FetchOptions GetFetchOption() const
Gets the fetch option that controls how requests are handled.
Definition: PartitionsRequest.h:165
PartitionsRequest & WithAdditionalFields(AdditionalFields additional_fields)
Sets the list of additional fields.
Definition: PartitionsRequest.h:98
Rules all the other namespaces.
Definition: AppleSignInProperties.h:24