olp-cpp-sdk  1.22.0
DataRequest.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 
26 #include <olp/core/thread/TaskScheduler.h>
27 #include <olp/dataservice/read/DataServiceReadApi.h>
28 #include <olp/dataservice/read/FetchOptions.h>
29 #include <boost/optional.hpp>
30 
31 namespace olp {
32 namespace dataservice {
33 namespace read {
34 
43 class DATASERVICE_READ_API DataRequest final {
44  public:
50  inline const boost::optional<std::string>& GetPartitionId() const {
51  return partition_id_;
52  }
53 
65  boost::optional<std::string> partition_id) {
66  partition_id_ = std::move(partition_id);
67  return *this;
68  }
69 
80  inline DataRequest& WithPartitionId(std::string&& partition_id) {
81  partition_id_ = std::move(partition_id);
82  return *this;
83  }
84 
96  inline const boost::optional<std::string>& GetDataHandle() const {
97  return data_handle_;
98  }
99 
112  inline DataRequest& WithDataHandle(boost::optional<std::string> data_handle) {
113  data_handle_ = std::move(data_handle);
114  return *this;
115  }
116 
129  inline DataRequest& WithDataHandle(std::string&& data_handle) {
130  data_handle_ = std::move(data_handle);
131  return *this;
132  }
133 
144  inline const boost::optional<std::string>& GetBillingTag() const {
145  return billing_tag_;
146  }
147 
157  inline DataRequest& WithBillingTag(boost::optional<std::string> tag) {
158  billing_tag_ = std::move(tag);
159  return *this;
160  }
161 
172  inline DataRequest& WithBillingTag(std::string&& tag) {
173  billing_tag_ = std::move(tag);
174  return *this;
175  }
176 
185  inline FetchOptions GetFetchOption() const { return fetch_option_; }
186 
197  inline DataRequest& WithFetchOption(FetchOptions fetch_option) {
198  fetch_option_ = fetch_option;
199  return *this;
200  }
201 
209  inline uint32_t GetPriority() const { return priority_; }
210 
218  inline DataRequest& WithPriority(uint32_t priority) {
219  priority_ = priority;
220  return *this;
221  }
222 
231  inline std::string CreateKey(const std::string& layer_id,
232  boost::optional<int64_t> version) const {
233  std::stringstream out;
234  out << layer_id << "[";
235  if (GetPartitionId()) {
236  out << GetPartitionId().get();
237  } else if (GetDataHandle()) {
238  out << GetDataHandle().get();
239  }
240  out << "]";
241  if (version) {
242  out << "@" << version.get();
243  }
244  if (GetBillingTag()) {
245  out << "$" << GetBillingTag().get();
246  }
247  out << "^" << GetFetchOption();
248  return out.str();
249  }
250 
251  private:
252  boost::optional<std::string> partition_id_;
253  boost::optional<int64_t> catalog_version_;
254  boost::optional<std::string> data_handle_;
255  boost::optional<std::string> billing_tag_;
256  FetchOptions fetch_option_{OnlineIfNotFound};
257  uint32_t priority_{thread::NORMAL};
258 };
259 
260 } // namespace read
261 } // namespace dataservice
262 } // namespace olp
Encapsulates the fields required to request data for the given catalog, layer, and partition.
Definition: DataRequest.h:43
const boost::optional< std::string > & GetDataHandle() const
Get the partition data handle.
Definition: DataRequest.h:96
DataRequest & WithBillingTag(std::string &&tag)
Sets the billing tag for the request.
Definition: DataRequest.h:172
DataRequest & WithPartitionId(boost::optional< std::string > partition_id)
Sets the partition ID.
Definition: DataRequest.h:64
DataRequest & WithBillingTag(boost::optional< std::string > tag)
Sets the billing tag for the request.
Definition: DataRequest.h:157
std::string CreateKey(const std::string &layer_id, boost::optional< int64_t > version) const
Creates a readable format for the request.
Definition: DataRequest.h:231
DataRequest & WithPriority(uint32_t priority)
Sets the priority of the request.
Definition: DataRequest.h:218
FetchOptions GetFetchOption() const
Gets the fetch option that controls how requests are handled.
Definition: DataRequest.h:185
const boost::optional< std::string > & GetPartitionId() const
Gets the ID of the requested partition.
Definition: DataRequest.h:50
const boost::optional< std::string > & GetBillingTag() const
Gets the billing tag to group billing records together.
Definition: DataRequest.h:144
DataRequest & WithDataHandle(boost::optional< std::string > data_handle)
Sets the partition data handle.
Definition: DataRequest.h:112
DataRequest & WithDataHandle(std::string &&data_handle)
Sets the partition data handle.
Definition: DataRequest.h:129
DataRequest & WithFetchOption(FetchOptions fetch_option)
Sets the fetch option that you can use to set the source from which data should be fetched.
Definition: DataRequest.h:197
DataRequest & WithPartitionId(std::string &&partition_id)
Sets the partition ID.
Definition: DataRequest.h:80
uint32_t GetPriority() const
Gets the request priority.
Definition: DataRequest.h:209
Rules all the other namespaces.
Definition: AppleSignInProperties.h:24